DllImport Unmanaged, Non .NET Dll to .NET Project Representing Char * and Void __StdCall

末鹿安然 提交于 2019-12-01 22:58:31

For an unmanaged DLL you do not add it as a reference. Make sure the binary DLL is located in the same folder as the build where the .NET EXE project resides in usually {project}\bin\debug.

Also, make sure that you had a .DEF file for the exports when you built the unmanaged DLL with Borland C++.

Edit:

LIBRARY Project1
EXPORTS
    CustomerForm

And in your Borland C++ source make sure that the function is declared as export, for an example:

#ifdef __cplusplus
__declspec(dllexport) void CustomerForm(char *s);
#endif

Using this will ensure that the function is exportable and can be linked!

Make sure the signature of your DllImport attribute matches up to the signature of your native C++ Dll i.e.

[DllImport ("Project1.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern void CustomerForm(string caption);

Hope this helps, Best regards, Tom.

To use DllImport, you don't need to add a reference of the dll, just put the dll beside your executable or in system32 and it should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!