您的位置:首页 > 编程语言 > C语言/C++

C++/C#结构体转化-传string给C++

2015-11-10 14:47 519 查看
此例是把C#结构传给C++

C++:

typedef struct VidyoClientInEventGroupChat_

{

/*! Message (contents) to be sent to all remote participants */

char message[MAX_CHAT_MESSAGE_LEN];

} VidyoClientInEventGroupChat;

C#:

[StructLayout(LayoutKind.Sequential)]

public struct VidyoClientInEventGroupChat

{

unsafe fixed byte message[MAX_CHAT_MESSAGE_LEN];

public unsafe bool SetMessage(string message)

{

byte[] bytes = UnicodeStringToUtf8Array(message);

if (bytes.Length > MAX_CHAT_MESSAGE_LEN)

{

return false;

}

fixed (VidyoClientInEventGroupChat* p = &this)

for (int i = 0; i < bytes.Length; i++)

{

p->message[i] = bytes[i];

}

return true;

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: