不吃饭,裸体等答案
c++原型:
typedef struct {
BYTE sSerialNumber[12]; //序列号
BYTE byAlarmInPortNum; //DVR报警输入个数
BYTE byAlarmOutPortNum; //DVR报警输出个数
BYTE byDiskNum; //DVR 硬盘个数
BYTE byDVRType; //DVR类型,
BYTE byChanNum; //DVR 通道个数
BYTE byStartChan; //起始通道号,例如DVS-1,DVR - 1
}NET_DVR_DEVICEINFO, *LPNET_DVR_DEVICEINFO;
LONG __stdcall NET_DVR_Login(char *sDVRIP,WORD wDVRPort,
char *sUserName,char *sPassword,LPNET_DVR_DEVICEINFO lpDeviceInfo);
c++代码测试正确
用c#转换代码如下:
public struct NET_DVR_DEVICEINFO
{
public byte[] sSerialNumber;
public byte byAlarmInPortNum;
public byte byAlarmOutPortNum;
public byte byDiskNum;
public byte byDVRType;
public byte byChanNum;
public byte byStartChan;
}
c#调用:
[DllImport( "HCNetSDK.dll ", EntryPoint = "NET_DVR_Login ", CallingConvention = CallingConvention.StdCall)]
private static extern Int32 NET_DVR_Login(string sDVRIP, Int16 wDVRPort, string sUserName, string sPassword, ref NET_DVR_DEVICEINFO lpDeviceInfo);
出现 "
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。 "错误
请教高手们,哪里出错了呢
------解决方案--------------------public struct NET_DVR_DEVICEINFO
{
[MarshalAs(UnManageType.ByValArray,SizeConst=12)]//要加上这句!
public byte[] sSerialNumber;
public byte byAlarmInPortNum;
public byte byAlarmOutPortNum;
public byte byDiskNum;
public byte byDVRType;
public byte byChanNum;
public byte byStartChan;
}
------解决方案--------------------获取硬件信息源代码(包括CPU,内存,硬盘信息):
http://www.msproject.cn/Article/GetHardwareInformation.aspx
希望有帮助