问题:要在vb中调用vc编写的dll:LPKernel.dll
在调用的时候程序会死掉,不知道是不是我参数写的有问题,还是结构体的问题,由于vc中的结构体是链表形式,改写成vb以后,我不知道是不是有问题,并且参数里也有结构体指针,请大家帮忙看看问题出在哪里。vc:
typedef struct _LPR_RESULT
{
struct _LPR_RESULT* pNext; //头,下一个识别结果的指针 char license[16]; //车牌
char color[8]; //颜色
int nColor;
int type; //车牌类型
int reliability; //整牌可信度
RECT location; //车牌在整个图像中的位置
int bright; //亮度评价 //时间
int msDecode; //解码图片的时间
int msDetect; //车牌检测的时间
int msLocate; //定位的时间
int msRecognise; //识别的时间
int msEncode; //压缩生成图片的时间
//.....
LPBYTE pBits; //整车图片,当设置为同一车仅上送一次结果的时候,内部是该结果的图片
int cbBits; //长度,应该等于传递进来的图片的数据的长度
//.....
DWORD dwReserved[61]; //保留
}LPR_RESULT;
BOOL WINAPI LPR_File(char * lpszFileName, LPR_RESULT* pResult, int cbBuffer, char * lpszPlateFile);
参数说明:
* BOOL __stdcall : 是否识别成功
* char * lpszFileName : IN 图像文件名
* LPR_RESULT* pResult : OUT 识别结果
* int cbBuffer : IN 识别结果缓冲区长度
* lpszPlateFile : 截取的车牌部分图片保存成文件,只支持bmp和jpg格式,NULL 不保存
vb里我是这样写的:
Public Type LPR_RESULT
pNext As Long '头,下一个识别结果的指针
license As String * 16 '车牌
color As String * 8 '颜色
nColor As Long
type As Long '车牌类型
reliability As Long '整牌可信度
location As RECT '车牌在整个图像中的位置
bright As Long '亮度评价 '时间
msDecode As Long '解码图片的时间
msDetect As Long '车牌检测的时间
msLocate As Long '定位的时间
msRecognise As Long '识别的时间
msEncode As Long '压缩生成图片的时间
pBits As Long '整车图片,当设置为同一车仅上送一次结果的时候,内部是该结果的图片
cbBits As Long '长度,应该等于传递进来的图片的数据的长度
dwReserved(0 To 60) As Long '保留
End TypePrivate Declare Function LPR_File Lib "LPKernel.dll" (ByVal imgfile_name As String, ByRef pResult As LPR_RESULT, ByVal cbbuffer As Long, ByVal platefile_name As String) As BooleanPrivate Sub Command1_Click()
Dim imgfilename As String
Dim imgplatename As String
Dim result As LPR_RESULT
Dim addresspt As LPR_RESULT
Const OFN_ALLOWMULTISELECT = &H200& '打开多个文件
Const cdlOFNExplorer = &H80000 'commandialog的样式
CommonDialog1.Flags = &H200
CommonDialog1.InitDir = App.Path '初始化路径,可不设
CommonDialog1.Filter = "图像文件 *.jpg|*.jpg|图像文件 *.bmp|*.bmp|图像文件 *.tif|*.tif" '过滤器
CommonDialog1.FileName = "" '初始化filename为空
CommonDialog1.ShowOpen '打开对话框
CommonDialog1.FileName = CommonDialog1.FileName & Chr(32) '文件名放入filename中,多文件时可以当数组使用,直接取出
imgfilename = CommonDialog1.FileName
imgplatename = "c:\1.bmp"
Image1.Picture = LoadPicture(imgfilename)
Dim i As Long
result.pNext = VarPtr(addresspt)If (LPR_File(imgfilename, result, Len(result), imgplatename) = False) Then
MsgBox ("识别失败")
Else
MsgBox ("识别成功")
End If
在调用的时候程序会死掉,不知道是不是我参数写的有问题,还是结构体的问题,由于vc中的结构体是链表形式,改写成vb以后,我不知道是不是有问题,并且参数里也有结构体指针,请大家帮忙看看问题出在哪里。vc:
typedef struct _LPR_RESULT
{
struct _LPR_RESULT* pNext; //头,下一个识别结果的指针 char license[16]; //车牌
char color[8]; //颜色
int nColor;
int type; //车牌类型
int reliability; //整牌可信度
RECT location; //车牌在整个图像中的位置
int bright; //亮度评价 //时间
int msDecode; //解码图片的时间
int msDetect; //车牌检测的时间
int msLocate; //定位的时间
int msRecognise; //识别的时间
int msEncode; //压缩生成图片的时间
//.....
LPBYTE pBits; //整车图片,当设置为同一车仅上送一次结果的时候,内部是该结果的图片
int cbBits; //长度,应该等于传递进来的图片的数据的长度
//.....
DWORD dwReserved[61]; //保留
}LPR_RESULT;
BOOL WINAPI LPR_File(char * lpszFileName, LPR_RESULT* pResult, int cbBuffer, char * lpszPlateFile);
参数说明:
* BOOL __stdcall : 是否识别成功
* char * lpszFileName : IN 图像文件名
* LPR_RESULT* pResult : OUT 识别结果
* int cbBuffer : IN 识别结果缓冲区长度
* lpszPlateFile : 截取的车牌部分图片保存成文件,只支持bmp和jpg格式,NULL 不保存
vb里我是这样写的:
Public Type LPR_RESULT
pNext As Long '头,下一个识别结果的指针
license As String * 16 '车牌
color As String * 8 '颜色
nColor As Long
type As Long '车牌类型
reliability As Long '整牌可信度
location As RECT '车牌在整个图像中的位置
bright As Long '亮度评价 '时间
msDecode As Long '解码图片的时间
msDetect As Long '车牌检测的时间
msLocate As Long '定位的时间
msRecognise As Long '识别的时间
msEncode As Long '压缩生成图片的时间
pBits As Long '整车图片,当设置为同一车仅上送一次结果的时候,内部是该结果的图片
cbBits As Long '长度,应该等于传递进来的图片的数据的长度
dwReserved(0 To 60) As Long '保留
End TypePrivate Declare Function LPR_File Lib "LPKernel.dll" (ByVal imgfile_name As String, ByRef pResult As LPR_RESULT, ByVal cbbuffer As Long, ByVal platefile_name As String) As BooleanPrivate Sub Command1_Click()
Dim imgfilename As String
Dim imgplatename As String
Dim result As LPR_RESULT
Dim addresspt As LPR_RESULT
Const OFN_ALLOWMULTISELECT = &H200& '打开多个文件
Const cdlOFNExplorer = &H80000 'commandialog的样式
CommonDialog1.Flags = &H200
CommonDialog1.InitDir = App.Path '初始化路径,可不设
CommonDialog1.Filter = "图像文件 *.jpg|*.jpg|图像文件 *.bmp|*.bmp|图像文件 *.tif|*.tif" '过滤器
CommonDialog1.FileName = "" '初始化filename为空
CommonDialog1.ShowOpen '打开对话框
CommonDialog1.FileName = CommonDialog1.FileName & Chr(32) '文件名放入filename中,多文件时可以当数组使用,直接取出
imgfilename = CommonDialog1.FileName
imgplatename = "c:\1.bmp"
Image1.Picture = LoadPicture(imgfilename)
Dim i As Long
result.pNext = VarPtr(addresspt)If (LPR_File(imgfilename, result, Len(result), imgplatename) = False) Then
MsgBox ("识别失败")
Else
MsgBox ("识别成功")
End If
pBits As Byte (或者Byte())
license(16-1) as byte
color(8-1) as byte
再用下面提供的方法用 AChars(result.license) 方式存取字符串值
Option ExplicitPrivate Declare Function lstrcpyn Lib "kernel32.dll" Alias "lstrcpynA" (ByRef lpString1 As Any, ByRef lpString2 As Any, ByVal iMaxLength As Long) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByRef lpString As Any) As Long
Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByRef Destination As Any, ByVal Length As Long)Public Property Get AChars(Chars() As Byte) As String
Dim lLength As Long
lLength = lstrlen(Chars(0))
If lLength = 0 Then Exit Property
AChars = StrConv(LeftB(Chars, lLength), vbUnicode)
End PropertyPublic Property Let AChars(Chars() As Byte, ByVal RHS As String)
Dim a() As Byte
Dim lLength As Long
Dim lMaxLength As Long
lMaxLength = UBound(Chars) + 1
ZeroMemory Chars(0), lMaxLength
If LenB(RHS) = 0 Then Exit Property
a = StrConv(RHS & Chr(0), vbFromUnicode)
lLength = lstrlen(a(0))
If lLength = 0 Then Exit Property
lstrcpyn Chars(0), a(0), IIf(lLength > lMaxLength, lMaxLength, lLength)
End Property