问题描述
C++sdk文档中写的方法:函数原型:int__stdcallCapturePicture(HANLDEhandle,InfoEx*pResult,char*szFileName,char*szPlateFileName,Time*pTime);参数:HANLDEhandle:设备句柄InfoEx*pResult:识别结果char*szFileName:保存的图片文件名称(需要传入缓冲区)char*szPlateFileName:保存的车牌图片文件名称(需要传入缓冲区)Time*pTime:抓拍时间
给我的头文件源码中InfoEx和Time是这样定义的:typedefstructtag_InfoEx_e{intnLoopID;intnLoopPos;DIRECTdirect;DevicePlateInfostPlates;}InfoEx,*InfoEx;typedefDWORDDIRECT;#defineDIRECT_DOWN(0)//向下#defineDIRECT_UP(1)//向上#defineDIRECT_LEFT(2)//向左#defineDIRECT_RIGHT(3)//向右#defineUNKOWN(4)//未知#definePLATE_NUM_LEN(16)#defineCOLOR_LEN(8)typedefstruct_tagInfo{charaNum[PLATE_NUM_LEN];charaColor[COLOR_LEN];charaCColor[COLOR_LEN];floatfRealty;Rectroi;intnType;floatfLetterRealty[PLATE_NUM_LEN];}Info,*Info;typedefstruct_tagRect{intleft;inttop;intright;intbottom;}Rect,*Rect;typedefstruct_tagTime{WORDYear;WORDMonth;WORDDay;WORDHour;WORDMinute;WORDSecond;WORDMillisecond;}Time,*Time;
我C#的调用:publicstructLPRPlateInfoEx{publicintnLoopId{get;set;}publicintnLoopPos{get;set;}publicUInt32direct{get;set;}publicInfostPlates{get;set;}}publicstructPlateInfo{publicstringaPlateNum{get;set;}publicstringaColor{get;set;}publicstringaCColor{get;set;}publicfloatfRealty{get;set;}publicRectroi{get;set;}publicintnType{get;set;}publicfloatfLetterRealty{get;set;}}publicstructRect{publicintleft{get;set;}publicinttop{get;set;}publicintright{get;set;}publicintbottom{get;set;}}publicstructTime{publicUInt16Year{get;set;}publicUInt16Month{get;set;}publicUInt16Day{get;set;}publicUInt16Hour{get;set;}publicUInt16Minute{get;set;}publicUInt16Second{get;set;}publicUInt16Millisecond{get;set;}}[DllImport("xxx.dll",EntryPoint="CapturePicture",CharSet=CharSet.Auto,CallingConvention=CallingConvention.Cdecl)]publicstaticexternintCapturePicture(IntPtrhandle,refInfoExpResult,StringBuilderszFileName,StringBuilderszPlateFileName,refTimepTime);
调CapturePicture的时候报错Additionalinformation:对PInvoke函数“...”的调用导致堆栈不对称。原因可能是托管的PInvoke签名与非托管的目标签名不匹配。请检查PInvoke签名的调用约定和参数与非托管的目标签名是否匹配。网上查应该是C#和c++类型不匹配的问题。谁能帮我看看还有哪里不匹配
解决方案
解决方案二:
我这样写应该更清楚点typedefstructtag_InfoEx_e{intnLoopID;intnLoopPos;DIRECTdirect;DevicePlateInfostPlates;}InfoEx,*InfoEx;
publicstructPlateInfoEx{publicintnLoopId{get;set;}publicintnLoopPos{get;set;}publicUInt32direct{get;set;}publicInfostPlates{get;set;}}
---------------------------------------typedefDWORDDIRECT;#defineDIRECT_DOWN(0)//向下#defineDIRECT_UP(1)//向上#defineDIRECT_LEFT(2)//向左#defineDIRECT_RIGHT(3)//向右#defineUNKOWN(4)//未知#definePLATE_NUM_LEN(16)#defineCOLOR_LEN(8)typedefstruct_tagInfo{charaNum[PLATE_NUM_LEN];charaColor[COLOR_LEN];charaCColor[COLOR_LEN];floatfRealty;Rectroi;intnType;floatfLetterRealty[PLATE_NUM_LEN];}Info,*Info;
publicstructPlateInfo{publicstringaPlateNum{get;set;}publicstringaColor{get;set;}publicstringaCColor{get;set;}publicfloatfRealty{get;set;}publicRectroi{get;set;}publicintnType{get;set;}publicfloatfLetterRealty{get;set;}}
-----------------------------------typedefstruct_tagRect{intleft;inttop;intright;intbottom;}Rect,*Rect;
publicstructRect{publicintleft{get;set;}publicinttop{get;set;}publicintright{get;set;}publicintbottom{get;set;}}
-----------------------typedefstruct_tagTime{WORDYear;WORDMonth;WORDDay;WORDHour;WORDMinute;WORDSecond;WORDMillisecond;}Time,*Time;
publicstructTime{publicUInt16Year{get;set;}publicUInt16Month{get;set;}publicUInt16Day{get;set;}publicUInt16Hour{get;set;}publicUInt16Minute{get;set;}publicUInt16Second{get;set;}publicUInt16Millisecond{get;set;}}
解决方案三:
http://stackoverflow.com/questions/30399339/marshalling-float-array-to-c-sharp参照这个搞定了。。。。来人回复送分~