求助:C#调用C++ dll 二级指针参数问题

go_go_runner 2012-10-24 03:08:17
最近的工作中要用c#调用c++写的dll里的方法,

C++里声明如下:

typedef struct _ScSystemTime
{
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
}ScSystemTime;

//查询视频文件
//参数 hVas VAS句柄
// nChannelNum 通道号
// stBeginTime 起始时间
// ScEndTime 结束时间
// szFileName 保存文件名称的数组指针 szFileMsg[][256] 每一个元素 前128个字节是存的文件名称,后面存的是文件创建时间/文件名/文件创建时间/文件大小,内存为内部申请
// 外部调用NVRSDK_DeleteMem 释放
// nItemNum 数组大小
//返回值 0表示失败 1表示成功
VASSDK_API long NVRSDK_SearchVideoFile(NVRHANDLE hVas,unsigned int nChannelNum,ScSystemTime stBeginTime,ScSystemTime ScEndTime,char ***szFileMsg,unsigned int *nItemNum);

c#代码:
[StructLayout(LayoutKind.Sequential)]
public struct SystemTime
{
public SystemTime(DateTime dt)
{
this.wYear = Convert.ToUInt16(dt.Year);
this.wMonth = Convert.ToUInt16(dt.Month);
this.wDayOfWeek = Convert.ToUInt16(dt.DayOfWeek);
this.wDay = Convert.ToUInt16(dt.Day);
this.wHour = Convert.ToUInt16(dt.Hour);
this.wMinute = Convert.ToUInt16(dt.Minute);
this.wSecond = Convert.ToUInt16(dt.Second);
this.wMilliseconds = Convert.ToUInt16(dt.Millisecond);
}
internal UInt16 wYear;
internal UInt16 wMonth;
internal UInt16 wDayOfWeek;
internal UInt16 wDay;
internal UInt16 wHour;
internal UInt16 wMinute;
internal UInt16 wSecond;
internal UInt16 wMilliseconds;
}

[DllImport("NVRClientSDK.dll")]
public static extern Int32 NVRSDK_SearchVideoFile(IntPtr vasConnectPtr, UInt32 channelNumber, SystemTime startDT, SystemTime endDT, IntPtr fileNamePtr, ref UInt32 fileCount);

调用:
//查找通道0的文件列表
VionClient.SystemTime startDT = new SystemTime(DateTime.Parse("2012-10-23 08:00:00"));
VionClient.SystemTime endDT = new SystemTime(DateTime.Parse("2012-10-23 23:00:00"));
UInt32 totalVideoFileCount = 0;
IntPtr returnAddr = new IntPtr();
value = VTVAS_ConnectVas(ip_Ptr);//value为IntPtr类型
UInt32 channelNumber = 0;
Int32 isSuccess = NVRSDK_SearchVideoFile(value, channelNumber, startDT, endDT, returnAddr, ref totalVideoFileCount);
执行上步显示
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。 觉得是哪个参数类型没对应好,另外char ***szFileMsg 这二级指针该 怎么获取,望高手解答。
...全文
119 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,547

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧