使用std :: string

时间:2015-07-10 06:58:24

标签: c# c++ marshalling

我尝试将结构编组到我的DLL的函数中。我的DLL是用C ++编写的,并接受ansi字符串。

// C++ signature
__declspec(dllexport) unsigned long __stdcall fn_func(struct st_Mystruct* stMystruct);

// The Structure in C++
#pragma pack(1) 

struct st_Mystruct{

    st_Mystruct()
    {
        string1 = "";
        string2 = "";
        string3 = "";
    }


    std::string string1;
    std::string string2;
    std::string string3;
};

#pragma pack() 

// C# Import
[DllImport("MyDll.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint fn_func([In, MarshalAs(UnmanagedType.LPStruct, SizeParamIndex = 1)] ref st_Mystruct stMystruct);

如何在C#中声明和编组结构?

0 个答案:

没有答案