又是C++函数转C#的问题

yinrongg 2010-10-11 02:20:52
尝试了好多次都没成功,只好来这里需帮助。
C++函数原型:
int VC_GetPlateCarInfo(unsigned char *pImageDir,char *szPlate,WORD *Top,WORD *Left,WORD *Bottom,WORD *Right, int Type)

函 数 名:VC_GetPlateCarInfo
参数说明:
(in) pImageDir:识别的图像路径, 数据类型:unsigned char *;
(out) szPlate:识别返回的车牌号码结果,
数据类型:Char *;
(out) iTop,iLeft,iBottom,iRight:返回的车牌的坐标,
数据类型:Word *;
(in) Type :识别的图像类型,4:jpg,99:bmp, 数据类型:int

转成的C#代码:
[DllImport("OutPutDLL.dll", EntryPoint = "VC_InitGetPlate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int GetPlateCarInfo(string pImageDir, StringBuilder szPlate, UInt16 Top, UInt16 Left, UInt16 Bottom, UInt16 Right, int Type);

C#函数调用:
 UInt16 top = new UInt16(), left = new UInt16(), bottom = new UInt16(), right = new UInt16();
StringBuilder strBld=new StringBuilder(255);
MessageBox.Show(GetPlateCarInfo(filePath, strBld, top, left, bottom, right, 4).ToString());


C++函数的char * iTop,iLeft,iBottom,iRight因为是out 参数,对应的C#我也使用过ref/out 。但还是出不了正确结果。大家提提高见!
...全文
228 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xszhou1997 2010-12-03
  • 打赏
  • 举报
回复
VC_InitGetPlate有参数吗?
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zhouzhangkui 的回复:]
返回值的参数加上ref
其余的按照类型去修改就行了
[/Quote]
周药师 2010-10-11
  • 打赏
  • 举报
回复
返回值的参数加上ref
其余的按照类型去修改就行了
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
char *JpegFileName=new char[255];
CString mystr;
mystr.Format(PathName);
//识别
strcpy(JpegFileName,mystr);

char *HPHM=new char[500];
WORD *Top=new WORD;
WORD *Left=new WORD;
WORD *Bottom=new WORD;
WORD *Right=new WORD;
//WORD *Top,*Left,*Bottom,*Right;//:获得车牌结果坐标

int result =GetPlateCarInfoFUNCTION(JpegFileName,HPHM,Top,Left,Bottom,Right,4);
这是 C++的代码,直接调用C++的函数原型,正常。
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 qiuxin425 的回复:]
[DllImport("OutPutDLL.dll", EntryPoint = "VC_InitGetPlate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

public static int GetPlateCarInfo(string pImageDir, ref String……
[/Quote] 不行。。。
qiuxin425 2010-10-11
  • 打赏
  • 举报
回复
如果这样不行我就不清楚了 应该不会出问题的
qiuxin425 2010-10-11
  • 打赏
  • 举报
回复
[DllImport("OutPutDLL.dll", EntryPoint = "VC_InitGetPlate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

public static int GetPlateCarInfo(string pImageDir, ref StringBuilder szPlate, ref UInt16 Top, ref UInt16 Left, ref UInt16 Bottom, ref UInt16 Right, int Type);

top = new UInt16(), left = new UInt16(), bottom = new UInt16(), right = new UInt16();
StringBuilder strBld=new StringBuilder(255);
MessageBox.Show(GetPlateCarInfo(filePath,ref strBld, ref top, ref left, ref bottom, ref right, 4).ToString());
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 qiuxin425 的回复:]
你要是址传递前面加ref,调用函数的前面也要加ref,你是不是只加了一个地方?
[/Quote] 都加了 。ref/out 都使用过。
qiuxin425 2010-10-11
  • 打赏
  • 举报
回复
你要是址传递前面加ref,调用函数的前面也要加ref,你是不是只加了一个地方?
chazikai24 2010-10-11
  • 打赏
  • 举报
回复
StringBuilder szPlate改 ref StringBuilder szPlate
UInt16 Bottom改 ref UInt16 Bottom
一般要返回的前面要加ref
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qiuxin425 的回复:]
C#的输出参数前好像要加out
[/Quote] 我说明了哦,加了out 也没用~
qiuxin425 2010-10-11
  • 打赏
  • 举报
回复
C#的输出参数前好像要加out
yinrongg 2010-10-11
  • 打赏
  • 举报
回复
沉了、、、、、、、、、、、、、、、、、、、、、、、
yinrongg 2010-10-11
  • 打赏
  • 举报
回复

111,129

社区成员

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

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

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