3

I have created a C++ dll ( let say , MyC++Dll.dll) and I have a header file ( MyC++Dll.h ). MyC++Dll.h contains the types definition .

I want to import this dll in C# application I am creating .

I am able to import the dll using

[DllImport("MyC++Dll.dll")] static extern func();

But I am not able to import/include the header file (MyC++Dll.h) in the C# application which contains the types definition .

Please suggest a way to build this C# application successfully .

Rakesh Agarwal
  • 3,009
  • 9
  • 33
  • 40
  • You have to use DllImport for every function you need to use from the DLL. If you post the C++ definitions of these from the header file, we could probably help you with the DllImport statements – John Sibly Feb 18 '09 at 12:43

3 Answers3

5

You have to convert any non-standard parameter types (i.e. custom structures, etc.) to C# by hand. Look at http://pinvoke.net for examples of how to do this with Win32 structures. You should be able to figure out how to do this for your own structures.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
0

The only way I know to do it is to create all the type definitions in C# manually, making sure they are compatible with your dll.

Grzenio
  • 35,875
  • 47
  • 158
  • 240
0

And you would also need to learn how to marshal types from C++ to C#.

Elroy
  • 605
  • 4
  • 12
  • 20