1

I wrote total native C++ code dll and I want to call his method thru C# code using P/Invoke. Do I need to change something in the properties of the native dll for this ?

Nate
  • 30,286
  • 23
  • 113
  • 184
Yanshof
  • 9,659
  • 21
  • 95
  • 195

2 Answers2

3

P/Invoking requires the stdcall convention. So look if all your functions declarations are preceeded by __stdcall. Otherwise the stack gets corrupted.

Also look at PInvokeStackImbalance C# call to unmanaged C++ function

Community
  • 1
  • 1
1

No, you don't need to change the properties of the DLL itself, but you need to make sure that the calling conventions match with those used in C#. Then you need to declare your callable functions in C# with matching argument and return types of those in C++.

Now you can call your functions in C#.

Besides the calling convention thing for your C++ functions, it should be fairly easy.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415