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

前端 未结 2 551
轮回少年
轮回少年 2021-01-23 02:40

I have a DLL non .net and unmanaged written in Borland C++ that I need to import. It returns void and has the identifier __stdcall on the function. It also requires passing of c

相关标签:
2条回答
  • 2021-01-23 03:25

    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.

    0 讨论(0)
  • 2021-01-23 03:37

    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.

    0 讨论(0)
提交回复
热议问题