C#调用C++ DLL(结构体中二维数组转换)
想在C# WinForm开发中调用一个采用C++封装好的dll, 但其结构体中的二维数组不知道应当如何转换, 网上搜索了一把P/Invoke资料相对来说比较少, 没有找到切实有用的文章, 现在调用虽不会报错了, 但没有产生预期效果.
#define MAX_STRM_LAYER 3 // 最多几级流媒体
//服务器信息
typedef struct tagServerInfo
{
long uID;
char csStrMIP[MAX_STRM_LAYER][16]; // 这个不知道如何转换
unsigned short nStrMPort[MAX_STRM_LAYER];
char csDdtIP[16];
unsigned short nDdtPort;
unsigned short bIsWebUser;
unsigned short protocolType;
const char *pcUserName;
const char *pcPassword;
char csStoreFileSvrIP[16];
unsigned short nStoreFileSvrPort;
char csDevFileSvrIP[16];
unsigned short nDevFileSvrPort;
}TServerInfo, *LPServerInfo;
LONG __stdcall StrM_Login(LPServerInfo mts, int iLayer = 1);
/// <summary>
/// 最多几级流媒体
/// </summary>
public const int MAX_STRM_LAYER = 3;
/// <summary>
/// 服务器信息
/// </summary>
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TServerInfo
{
public int uID;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.LPStr)]
public string[] csStrMIP;
public ushort[] nStrMPort;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 16)]
public string csDdtIP;
public ushort nDdtPort;
public ushort bIsWebUser;
public ushort protocolType;
public string pcUserName;
public string pcPassword;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 16)]
public string csStoreFileSvrIP;
public ushort nStoreFileSvrPort;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 16)]
public string csDevFileSvrIP;
public ushort nDevFileSvrPort;
}
[DllImport("StreamMedia.dll")]
public static extern int StrM_Login(ref TServerInfo mts, int iLayer);
...全文
相关推荐
基于C#调用c++Dll结构体数组指针的问题详解
下面小编就为大家分享一篇基于C#调用c++Dll结构体数组指针的问题详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
C#调用C++dll 结构体参数传递问题
1、最近做项目遇到,C#调用C++dll里的函数需要传递结构体参数,发现这个并不是简单的在C#里定义相应的结构体就可以的,下面以一个例子来说明解决的办法,C++中的函数和结构体如下: uint msec_set_igr_gen_cfg(int port, IGR_GEN_T *igr_gen) { return 0; } typedef struct { i
C#调用C++DLL传递结构体数组的终极解决方案
主要介绍了C#调用C++DLL传递结构体数组的终极解决方案的相关资料,需要的朋友可以参考下
C#调用C++ Dll关于结构体数组引用的传递及解析使用的展示代码
资源代码演示的是c#代码调用c++ DLL 的方式。该演示为原创,绝非搬砖。解决了c# 调用 C++ Dll获取相关信息之如何传递结构体数组引用以及如何处理获取到的结构体数组数据的问题。
C#调用C++封装成DLL的结构体及类
C#调用C++封装成DLL的结构体及类


