equivalent char* in C#

后端 未结 5 533
深忆病人
深忆病人 2020-11-30 13:02

I have a dll that is written in c++. And I am p/invoking to call the functions.

I have this c++ declaration.

int dll_registerAccount(char* username,          


        
5条回答
  •  猫巷女王i
    2020-11-30 13:55

    Be aware of calling conventions, this tripped me up. In my case I need to call a C++ DLL but with C-style exports, which uses the cdecl calling convention. If you have the luxury of having the source Visual Studio Solution, go to Properties -> C/C++ -> Advanced and find it under "Calling Convention". This fix it for me:

    [DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    // bool MyFunction(char* fileName) <-- From the DLL
    static extern bool MyFunction(string fileName);
    

提交回复
热议问题