C#调用C++ DLL(结构体中二维数组转换)

peterb peterb 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
想在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);

...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
peterb
C# 111,129 成员 642,539 内容