zoukankan      html  css  js  c++  java
  • C++/C#结构体转化-传string给C++

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

                }

            };

  • 相关阅读:
    Python中*和**的区别
    Python中str、list、numpy分片操作
    Python中bisect的使用方法
    Python中__str__和__repr__的区别
    Python中函数参数类型和参数绑定
    C++中explicit
    C++中const
    自动识别 URL
    .net中activex的替代技术:winform control(一)
    vs2005包加载有误的解决方法
  • 原文地址:https://www.cnblogs.com/acdyf/p/4953036.html
Copyright © 2011-2022 走看看