delphi 中
function StartReadCard(aHandle: THandle; ComPort: PChar; BaudRate: Integer; var Buffer: array of Byte; var DataLength: Integer): boolean; stdcall; external 'ReadCard.dll';var
buf: array[0..4] of Byte;
i: integer;
iDateLen: Integer;
sCommPort: string;
iCommType: Integer;
iIDReaderType: Byte;
iBaudRate: Integer;
sCardNo: string;
OriginalCardID:Int64; FillChar(buf, 5, 0);
sCommPort := 'com6';
iBaudRate := 9600;
if StartReadCard(Application.Handle, PChar(sCommPort), iBaudRate, buf, iDateLen) then
........
end ifVB中怎么写
Private Declare Function StartReadCard Lib "ReadCard.dll" (ByVal aHandle As Long, ByVal ComPort As String, ByVal BaudRate As Integer, ByRef Buffer As byte , ByRef DataLength As Long) As Boolean Dim buf() As byte
Dim i As Integer
Dim iDateLen As Long
Dim sCommPort As String
Dim iCommType As Integer
Dim iIDReaderType As Byte
Dim iBaudRate As Integer
Dim sCardNo As String
Dim OriginalCardID As Long sCommPort = "com6"
iBaudRate = 9600
ReDim buf(4)
For i = 0 To UBound(buf)
buf(i) = "0"
Next i
If StartReadCard(App.hInstance, sCommPort, iBaudRate, buf(0), VarPtr(iDateLen)) Then
............
end if到StartReadCard这,就报内存错误.
帮忙看下,哪有问题
function StartReadCard(aHandle: THandle; ComPort: PChar; BaudRate: Integer; var Buffer: array of Byte; var DataLength: Integer): boolean; stdcall; external 'ReadCard.dll';var
buf: array[0..4] of Byte;
i: integer;
iDateLen: Integer;
sCommPort: string;
iCommType: Integer;
iIDReaderType: Byte;
iBaudRate: Integer;
sCardNo: string;
OriginalCardID:Int64; FillChar(buf, 5, 0);
sCommPort := 'com6';
iBaudRate := 9600;
if StartReadCard(Application.Handle, PChar(sCommPort), iBaudRate, buf, iDateLen) then
........
end ifVB中怎么写
Private Declare Function StartReadCard Lib "ReadCard.dll" (ByVal aHandle As Long, ByVal ComPort As String, ByVal BaudRate As Integer, ByRef Buffer As byte , ByRef DataLength As Long) As Boolean Dim buf() As byte
Dim i As Integer
Dim iDateLen As Long
Dim sCommPort As String
Dim iCommType As Integer
Dim iIDReaderType As Byte
Dim iBaudRate As Integer
Dim sCardNo As String
Dim OriginalCardID As Long sCommPort = "com6"
iBaudRate = 9600
ReDim buf(4)
For i = 0 To UBound(buf)
buf(i) = "0"
Next i
If StartReadCard(App.hInstance, sCommPort, iBaudRate, buf(0), VarPtr(iDateLen)) Then
............
end if到StartReadCard这,就报内存错误.
帮忙看下,哪有问题
VB中怎么表示?
Option Explicit
'function StartReadCard(aHandle: THandle;
' ComPort: PChar;
' BaudRate: Integer;
' var Buffer:array of Byte;
' var DataLength: Integer): boolean; stdcall; external 'ReadCard.dll';
Private Declare Function StartReadCard Lib "ReadCard.dll" (ByVal aHandle As Long, _
ByVal ComPort As String, _
ByVal BaudRate As Long, _
Buffer() As Byte, _
ByVal DataLength As Long) As Boolean
Private Sub Form_Load()
Dim buf() As Byte
Dim i As Integer
Dim iDateLen As Long
Dim sCommPort As String
Dim iCommType As Integer
Dim iIDReaderType As Byte
Dim iBaudRate As Integer
Dim sCardNo As String
Dim OriginalCardID As Long
sCommPort = "COM6"
iBaudRate = 9600
ReDim buf(4)
For i = 0 To UBound(buf)
buf(i) = "0"
Next i
If StartReadCard(App.hInstance, sCommPort, iBaudRate, ByVal VarPtr(buf(0)), iDateLen) Then
End If
End Sub
[email protected]
是不是这个参数的原因啊?
Private Declare Function StartReadCard Lib "ReadCard.dll" (ByVal aHandle As Long, ByVal ComPort As String, ByVal BaudRate As Integer, Buffer() As Byte, ByVal DataLength As Long) As BooleanPrivate Sub Command1_Click()
Dim buf(4) As Byte
Dim i As Integer
Dim iDateLen As Long
Dim sCommPort As String
Dim iCommType As Integer
Dim iIDReaderType As Byte
Dim iBaudRate As Integer
Dim sCardNo As String
Dim OriginalCardID As Long
sCommPort = "com6"
iBaudRate = 9600 For i = 0 To 3
buf(i) = "0"
Next i
If StartReadCard(App.hInstance, sCommPort, iBaudRate, buf, VarPtr(iDateLen)) Then
......
end if
Dim buf(4) As Byte
Dim i As Integer
Dim iDateLen As integer
Dim sCommPort As String
Dim iCommType As Integer
Dim iIDReaderType As Byte
Dim iBaudRate As Integer
Dim sCardNo As String
Dim OriginalCardID As Long
sCommPort = "com6"
iBaudRate = 9600 For i = 0 To 3
buf(i) = "0"
Next i
If StartReadCard(App.hInstance, sCommPort, iBaudRate, buf, VarPtr(iDateLen)) Then
......
end if
改成这样,读卡不报内存错误,报溢出,是什么原因,为什么哪溢出?
这样运行报内存错误;
If StartReadCard(App.hInstance, sCommPort, iBaudRate, buf, varptr(iDateLen)) Then
这样运行报溢出.
Private Declare Function StartReadCard Lib "ReadCard.dll" (ByVal aHandle As Long, ByVal ComPort As Byte, ByVal BaudRate As Long, ByRef Buffer As byte , ByRef DataLength As Long) As Boolean
最后一个参数,byval,byref都试试看
最后下个参数byval,byref都一样,LONG内存错误,integer溢出.
在VB中怎么表示啊?
到dephi区去咨询一下各个参数的数据类型吧
Private Declare Function GetActiveWindow Lib "user32" () As LongPrivate Sub Command1_Click()
Dim buf(255) As Byte
Dim i As Integer
Dim iDateLen As Long
Dim sCommPort As String Dim iBaudRate As Long
Dim sCardNo As String
Dim OriginalCardID As Long
sCommPort = "com6"
iBaudRate = 9600 If StartReadCard(GetActiveWindow, sCommPort, iBaudRate, buf, iDateLen) Then
...
End If
End Sub现在改成这样了,但是报"接收卡号的BYTE数组长度必须大于4"
我怎么指定长度?
这样写法应该不对
改成:
If StartReadCard(GetActiveWindow, sCommPort, iBaudRate, buf(0), 256) Then
不报错误了,但读完以后又老样子了,内存错误.
然后调用时,pBuffer参数用指针传入:varptr(buf(0))最后一个参数直接传值试试看.另外,最好把DELPHI的数据长度弄到手,确定数据长度后再好搞.如果实在没有,那就直接用OD跟踪DELPHI版的程序调用,看看堆栈里到底压入了些什么信息.