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

            }

        };

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-30
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
相关资源
相似解决方案