码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-11-10 15:43:56      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

此例是把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;

            }

        };

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

标签:

原文地址:http://www.cnblogs.com/acdyf/p/4953036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!