Using C++ DLL in C# project
Try to switch your C# code from AnyCPU to x86 (in Properties dialog).
Your exported function uses the PASCAL
calling convention, which in Windows is the same as stdcall
. The .Net runtime needs to know about that, so modify your C# method signature as follows:
[DllImport("convert.dll", SetLastError = true, CallingConvention=CallingConvention.StdCall)]
static extern Int32 convert([MarshalAs(UnmanagedType.LPStr)] string filename);
try to use __stdcall
(or WINAPI
or APIENTRY
) in the function exported from the DLL.