急C#调用C++方法传入ref的结构体参数有关问题
急!!!C#调用C++方法传入ref的结构体参数问题!
C++的方法原型是这样的:
C++结构体是这样的:
给出的调用示例是这样的:
获取监控点资源(第一次调用获取资源数量,第二次调用获取详细信息)
C#的结构体定义:
C#的方法声明是这样的:
我的调用C#代码是这样的:
问题:第一次调用Plat_GetAllCamera的时候倒数第二个参数我这样传入null的时候,没有办法获取PlatRtnCam的真正值,所以后面就没有办法为传出参数pCameraInfo赋值了。求大家帮忙。真心谢谢了。
C++的方法原型是这样的:
int Plat_GetAllCamera(int iUserHandle,
int iNeedGetNum,
PLAT_CAMERAINFO* pCameraBuffer,
int* pOutputNum);
C++结构体是这样的:
//监控点信息结构体
typedef struct _tagCameraInfo
{
int iCameraID; //监控点ID
int iRegionID; //所属区域ID
int iControlCell; //所属中心ID
int iDeviceID; //设备ID
int iDeviceChannel; //通道号
char szCameraName[128]; //监控点名称
int iStoreType[4]; //监控点录像位置数组 0代表无录像,1代表有录像
//iStoreType[0] //代表是否有设备录像;
//iStoreType[1] //代表是否有PCNVR录像;
//iStoreType[2] //代表是否有NVR录像;
//iStoreType[3] //代表是都有CVR录像。
int iCameraState; //监控点状态
}PLAT_CAMERAINFO,*LPPLAT_CAMERAINFO;
给出的调用示例是这样的:
获取监控点资源(第一次调用获取资源数量,第二次调用获取详细信息)
//获取监控个数
if (-1 == Plat_GetAllCamera(g_iLoginHandle, 0,NULL, &PlatRtnCam))
{
iErrNum = Plat_GetLastError();
}
NeedReadCam = PlatRtnCam;
pCameraInfo = new (std::nothrow) PLAT_CAMERAINFO[NeedReadCam];
if (NULL == pCameraInfo)
break;
memset(pCameraInfo, 0, NeedReadCam * sizeof(PLAT_CAMERAINFO));
if (-1 == Plat_GetAllCamera(g_iLoginHandle, NeedReadCam, pCameraInfo, &PlatRtnCam))
{
iErrNum = Plat_GetLastError();
}
C#的结构体定义:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct _tagCameraInfo
{
public Int32 iCameraID; //监控点ID
public Int32 iRegionID; //所属区域ID
public Int32 iControlCell; //所属中心ID
public Int32 iDeviceID; //设备ID
public Int32 iDeviceChannel; //通道号
public byte[] szCameraName; //监控点名称
public Int32[] iStoreType; ////监控点录像位置数组 0代表无录像,1代表有录像;iStoreType[0]代表是否有设备录像;iStoreType[1]代表是否有PCNVR录像;iStoreType[2]代表是否有NVR录像;iStoreType[3]代表是都有CVR录像。
public Int32 iCameraState; //监控点状态
}
C#的方法声明是这样的:
[DllImport("PlatformSDK.dll", CharSet = CharSet.Ansi)]
public unsafe static extern int Plat_GetAllCamera(int iUserHandle, int iNeedGetNum, ref _tagCameraInfo[] pCameraBuffer, ref int pOutputNum);
我的调用C#代码是这样的:
int PlatRtnCam = 0;
_tagCameraInfo[] pCameraInfo = null;
if (-1 == Plat_GetAllCamera(g_iLoginHandle, 0, ref pCameraInfo, ref PlatRtnCam))
{
}
pCameraInfo = new _tagCameraInfo[PlatRtnCam];
for (int i = 0; i < pCameraInfo.Length; i++)
{
pCameraInfo[i].szCameraName = new byte[128];
pCameraInfo[i].iStoreType = new int[4];
}
int CamCount = PlatRtnCam;
if (-1 == Plat_GetAllCamera(g_iLoginHandle, CamCount, ref pCameraInfo, ref PlatRtnCam))
{
}
问题:第一次调用Plat_GetAllCamera的时候倒数第二个参数我这样传入null的时候,没有办法获取PlatRtnCam的真正值,所以后面就没有办法为传出参数pCameraInfo赋值了。求大家帮忙。真心谢谢了。