equivalent char* in C#

后端 未结 5 527
深忆病人
深忆病人 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条回答
  •  一生所求
    2020-11-30 13:44

    The C# way of doing this is by letting the marshaler handle the char* stuff while you work with a string:

    [DllImport("pjsipDlld")]
    static extern int dll_registerAccount(
        [MarshalAs(UnmanagedType.LPStr)]string username,
        [MarshalAs(UnmanagedType.LPStr)]string password);
    

    Replace LPStr with LPWStr if you're working with wide chars.

提交回复
热议问题