• C++/C#结构体转化-二维数组-bytes To Strings


    C++结构体

    typedef struct VidyoClientRequestGetWindowsAndDesktops_

    {

        /*! The number of application windows currently open */

        VidyoSizeT numApplicationWindows;

        /*! List of open application window names (UTF-8) (Localized) */

        char appWindowName[MAX_NUM_APP_WINDOWS][MAX_URI_LEN];

        /*! List of open application window application names (UTF-8) (Localized) */

        char appWindowAppName[MAX_NUM_APP_WINDOWS][MAX_URI_LEN];

        /*! List of open application window handles */

        VidyoWindowCapturerWindowId appWindowId[MAX_NUM_APP_WINDOWS];

        /*! List of open application window geometries */

        VidyoRect appWindowRect[MAX_NUM_APP_WINDOWS];

        /*! The number of system desktops currently available */

        VidyoSizeT numSystemDesktops;

        /*! List of available system desktop names (UTF-8) (Not localized) */

        char sysDesktopName[MAX_SHARE_DISPLAY_DEVICE][MAX_URI_LEN];

        /*! List of available system desktop handles */

        VidyoWindowCapturerWindowId sysDesktopId[MAX_SHARE_DISPLAY_DEVICE];

        /*! List of available system desktop geometries */

        VidyoRect sysDesktopRect[MAX_SHARE_DISPLAY_DEVICE];

    } VidyoClientRequestGetWindowsAndDesktops;

     

    C# 翻译

     [Serializable]

            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]

            unsafe public struct VidyoClientRequestGetWindowsAndDesktops

            {

                public uint numApplicationWindows;

     

                [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NUM_APP_WINDOWS * MAX_URI_LEN)]

                public byte[] appWindowName;

     

                [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NUM_APP_WINDOWS * MAX_URI_LEN)]

                public byte[] appWindowAppName;

     

                [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NUM_APP_WINDOWS)]

                public uint[] appWindowId;

     

     

     

                [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = MAX_NUM_APP_WINDOWS)]

                public VidyoRect[] appWindowRect;

     

                public uint numSystemDesktops;

     

                [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_SHARE_DISPLAY_DEVICE * MAX_URI_LEN)]

                public byte[] sysDesktopName;

     

                [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_SHARE_DISPLAY_DEVICE)]

                public uint[] sysDesktopId;

     

     

                [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = MAX_SHARE_DISPLAY_DEVICE)]

                public VidyoRect[] sysDesktopRect;

     

     

     

                public string[] GetappWindowList()

                {

                    int numApp = (int)(numApplicationWindows);

                    string[] appWindowList = new string[numApp];

                    byte[] bytUTF8 = new byte[MAX_URI_LEN];

                    for (int i = 0; i < numApplicationWindows; i++)

                    {

                        for (int j = 0; j < MAX_URI_LEN; j++)

                        {

                            bytUTF8[j] = appWindowName[j + i * Vidyo32.MAX_URI_LEN];

                        }

                        if (bytUTF8[0] != 0)

                        { appWindowList[i] = UnicodeStringFromUtf8Array(bytUTF8); }

                        else

                        { appWindowList[i] = ""; }

                    }

     

                    return appWindowList;

                }

                public string[] GetappWindowAppList()

                {

                    int numApp = (int)(numApplicationWindows);

                    string[] appWindowList = new string[numApp];

                    byte[] bytUTF8 = new byte[MAX_URI_LEN];

                    for (int i = 0; i < numApplicationWindows; i++)

                    {

                        for (int j = 0; j < MAX_URI_LEN; j++)

                        {

                            bytUTF8[j] = appWindowAppName[j + i * Vidyo32.MAX_URI_LEN];

                        }

                        if (bytUTF8[0] != 0)

                        { appWindowList[i] = UnicodeStringFromUtf8Array(bytUTF8); }

                        else

                        { appWindowList[i] = ""; }

                    }

     

                    return appWindowList;

                }

                public string[] GetDesktopList()

                {

                    int numApp = (int)(numSystemDesktops);

                    string[] appWindowList = new string[numApp];

                    byte[] bytUTF8 = new byte[MAX_URI_LEN];

                    for (int i = 0; i < numSystemDesktops; i++)

                    {

                        for (int j = 0; j < MAX_URI_LEN; j++)

                        {

                            bytUTF8[j] = sysDesktopName[j + i * Vidyo32.MAX_URI_LEN];

                        }

                        if (bytUTF8[0] != 0)

                        { appWindowList[i] = UnicodeStringFromUtf8Array(bytUTF8); }

                        else

                        { appWindowList[i] = ""; }

                    }

     

                    return appWindowList;

                }

            };

     

    static public string UnicodeStringFromUtf8Array(byte[] bytUTF8)

            {

                byte[] bytUnicode = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, bytUTF8);

                int cntUnicode = Encoding.Unicode.GetCharCount(bytUnicode);

                char[] charUnicode = Encoding.Unicode.GetChars(bytUnicode);

                int j = 0;

                for (; j < cntUnicode; j++)

                {

                    if (charUnicode[j] == 0)

                        break;

                }

                string strUnicode = Encoding.Unicode.GetString(bytUnicode, 0, j * 2);

                return strUnicode;

            }

  • 相关阅读:
    复杂分组查询 查询订单数量和订单总金额 根据国家分组
    left join 连接之后 where条件字段为空 解决办法
    virtual Box 搭建 centOS 步骤(优化卡顿设置)(卡、卡、卡)
    Redis学习Redis的应用场景
    C#设计模式2创建型模式2.4 抽象工厂模式(Abstract Factory Pattern)
    Redis学习Redis的高频面试题
    Redis学习.AspNet Core项目实际应用
    C#设计模式2创建型模式2.5 建造者模式(Builder Pattern)
    C#设计模式2创建型模式2.2简单工厂模式(Factory Method Pattern)
    C#设计模式2创建型模式2.6原型模式(Prototype Pattern)
  • 原文地址:https://www.cnblogs.com/acdyf/p/4953020.html
Copyright © 2020-2023  润新知