c#调用以前的Dll问题,请前辈帮小弟看下代码,小弟先感谢了!

salecn 2008-12-23 11:49:52
背景:
想用c#调用以前的DLL,原函数说明如下:
函数原型:int WINAPI TtFinger(unsigned char *FingerBuf);
函数功能:检测获取的数据是否是手指
函数参数:FingerBuf-读取的指纹数据,通过此指纹数据判断是否是手指.缓冲区大小304*256Byte。
返回值: 成功返回 1,失败返回 0。


问题:
以下是我的c#代码,我写到?????问号的地方就不知道应该怎样写了,请各位前辈帮小弟一把,小弟先感谢了!
[DllImport("test.dll", EntryPoint = "TtFinger", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int TtFinger(????????);


int zhuantai= TtFinger(??????????)



...全文
108 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimgreat 2008-12-23
  • 打赏
  • 举报
回复
unsigned char *FingerBuf 指纹数据在应该是字节数组吧
byte[] FingerBuf
halk 2008-12-23
  • 打赏
  • 举报
回复
最省事的办法是使用unsafe代码,原型抄过来就可以了,可以直接使用指针 TtFinger(byte * FingerBuf)

如果不用unsafe,这个地方就使用IntPtr: TtFinger(IntPtr FingerBuf),后面需要使用Marshal的方法接收缓冲区中的内容。
salecn 2008-12-23
  • 打赏
  • 举报
回复
哈哈,谢谢gomoku !! 解决了一个大问题!! 感谢 了!!
gomoku 2008-12-23
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 salecn 的回复:]
...
问题:这样调用后 result的值始终为0,估计问题会出到什么地方啊?
[/Quote]

你要传入数据啊,传入全是零的数组怎么会找到指纹呢?


byte[] FingerBuf = new byte[304 * 256];
FillData( FingerBuf ); //完成类似的功能
int result = TtFinger(FingerBuf);
salecn 2008-12-23
  • 打赏
  • 举报
回复
楼上的那个作废,有个函数写错了
各位前辈,问题又来了:
我把代码按楼上各位前辈的意思修改了,但

导入dll:
[DllImport("test.dll", EntryPoint = "TtFinger", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int TtFinger(byte[] FingerBuf);

调用:

byte[] FingerBuf = new byte[304 * 256];
int result = TtFinger(FingerBuf);

问题:这样调用后 result的值始终为0,估计问题会出到什么地方啊?
salecn 2008-12-23
  • 打赏
  • 举报
回复
各位前辈,问题又来了:
我把代码按楼上各位前辈的意思修改了,但

导入dll:
[DllImport("test.dll", EntryPoint = "TtFinger", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int TtFinger(byte[] FingerBuf);

调用:

byte[] FingerBuf = new byte[304 * 256];
int result = fingerfun.MXDetectFinger(FingerBuf);

问题:这样调用后 result的值始终为0,估计问题会出到什么地方啊?
xdf_hubei 2008-12-23
  • 打赏
  • 举报
回复
楼上正解...我错了...
gomoku 2008-12-23
  • 打赏
  • 举报
回复

[DllImport("abc.dll")]
public static extern int TtFinger(byte[] fingerBuf); // don't put a ref here
xdf_hubei 2008-12-23
  • 打赏
  • 举报
回复
想用c#调用以前的DLL,原函数说明如下:
函数原型:int WINAPI TtFinger(unsigned char *FingerBuf);
函数功能:检测获取的数据是否是手指
函数参数:FingerBuf-读取的指纹数据,通过此指纹数据判断是否是手指.缓冲区大小304*256Byte。
返回值: 成功返回 1,失败返回 0。

[DllImport("abc.dll")]
public static extern int TtFinger(ref byte[] fingerBuf);
用法:
byte[] buf = new byte[304*256];
int result = TfFinger(ref buf);
if(result == 1)
{
}
else
{
}

111,130

社区成员

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

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

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