Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换c++;API结构到c# 我试图把C++ API实例转换成C语言。但是我无法通过struct具有字符串类型的方式在struct中找到struct指针的方式。这里是C++结构和函数< /p> struct AuthParam { char server_ip[32]; char username[50]; char password[50]; }; struct CameraInfo { int index; char devicename[100]; char smallrtsp[1000]; char bigrtsp[1000]; }; struct SingleDevice { char deviceid[50]; char devicename[100]; int flag_onuse; int cameralist_size; CameraInfo* cameralist; }; struct DeviceList { int listsize; SingleDevice* singledevicelist; }; typedef int (WINAPI capi_init)(void); typedef int (WINAPI capi_disabled)(void); typedef int (WINAPI capi_GetServerTimeCode)(char* server_ip, unsigned int* timecode); typedef int (WINAPI GetDevicelist)(AuthParam auth_para, DeviceList* devicelist);_C#_C++_Pointers_Struct - Fatal编程技术网

转换c++;API结构到c# 我试图把C++ API实例转换成C语言。但是我无法通过struct具有字符串类型的方式在struct中找到struct指针的方式。这里是C++结构和函数< /p> struct AuthParam { char server_ip[32]; char username[50]; char password[50]; }; struct CameraInfo { int index; char devicename[100]; char smallrtsp[1000]; char bigrtsp[1000]; }; struct SingleDevice { char deviceid[50]; char devicename[100]; int flag_onuse; int cameralist_size; CameraInfo* cameralist; }; struct DeviceList { int listsize; SingleDevice* singledevicelist; }; typedef int (WINAPI capi_init)(void); typedef int (WINAPI capi_disabled)(void); typedef int (WINAPI capi_GetServerTimeCode)(char* server_ip, unsigned int* timecode); typedef int (WINAPI GetDevicelist)(AuthParam auth_para, DeviceList* devicelist);

转换c++;API结构到c# 我试图把C++ API实例转换成C语言。但是我无法通过struct具有字符串类型的方式在struct中找到struct指针的方式。这里是C++结构和函数< /p> struct AuthParam { char server_ip[32]; char username[50]; char password[50]; }; struct CameraInfo { int index; char devicename[100]; char smallrtsp[1000]; char bigrtsp[1000]; }; struct SingleDevice { char deviceid[50]; char devicename[100]; int flag_onuse; int cameralist_size; CameraInfo* cameralist; }; struct DeviceList { int listsize; SingleDevice* singledevicelist; }; typedef int (WINAPI capi_init)(void); typedef int (WINAPI capi_disabled)(void); typedef int (WINAPI capi_GetServerTimeCode)(char* server_ip, unsigned int* timecode); typedef int (WINAPI GetDevicelist)(AuthParam auth_para, DeviceList* devicelist);,c#,c++,pointers,struct,C#,C++,Pointers,Struct,这是我的c#代码,但我找不到在我得到的结构中定义结构指针的方法” 错误CS0208无法获取托管类型的地址、大小或声明指向托管类型的指针('Form1.CameraInfo')”错误 有没有办法实现这一转变 > P>我认为这个错误是因为C++(un托管代码)和C托管代码(托管代码)的不同性质,所以可能使用Sturn.ItpTR作为指针指向Struts结构。 请考虑这个问题,你可以找到哪个是一个开源工具,用来将代码从非托管代码转换为托管C代码。在一篇关于的小博客文章中,也许该行应该是public r

这是我的c#代码,但我找不到在我得到的结构中定义结构指针的方法” 错误CS0208无法获取托管类型的地址、大小或声明指向托管类型的指针('Form1.CameraInfo')”错误


有没有办法实现这一转变

> P>我认为这个错误是因为C++(un托管代码)和C托管代码(托管代码)的不同性质,所以可能使用Sturn.ItpTR作为指针指向Struts结构。
请考虑这个问题,你可以找到哪个是一个开源工具,用来将代码从非托管代码转换为托管C代码。在一篇关于

的小博客文章中,也许该行应该是
public ref SingleDevice SingleDevice
?或者您可以使用
IntPtr
作为指针。
public struct AuthParam
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string server_ip;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
            public string username;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
            public string password;
        };

        [StructLayout(LayoutKind.Sequential)]
        public struct CameraInfo
        {
            public int index;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string devicename;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1000)]
            public string smallrtsp;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1000)]
            public string bigrtsp;
        };

        [StructLayout(LayoutKind.Sequential)]
        public struct SingleDevice
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
            public string deviceid;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string devicename;
            public int flag_onuse;
            public int cameralist_size;

            public CameraInfo *cameralist;
        };

        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct DeviceList
        {
            public int listsize;
            public SingleDevice *singledevicelist;
        };

[DllImport("c:\\lib\\api_client.dll")] public static extern int capi_init();
        [DllImport("c:\\lib\\api_client.dll")] public static extern int capi_disabled();
        [DllImport("c:\\lib\\api_client.dll")] public static extern int capi_GetServerTimeCode(string ip, ref uint timecode);
        [DllImport("c:\\lib\\api_client.dll")] public static extern int GetDevicelist (AuthParam auth_para,ref  DeviceList devicelist);