0
私はC DLLを呼び出すVBプログラムを持っています。私はAccess for VBAで同じことをしようとしています。 VBコードが動作し、呼び出しが発生するとVBAがクラッシュするERPGetFingerprintImage(buff、tam_image)を呼び出します。 Byte Arrayインターフェイスがエラーを生成すると思います。VBが同じDLLを呼び出すときにVBAが呼び出されない理由
ヒント? ありがとうございます。ここで
は、VBのコードです:
Public Class Form1
Declare Sub ERPInitialize Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll" (ByVal hWnd As IntPtr)
Declare Sub ERPStartCapture Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll"()
Declare Sub ERPIsFingerCaptured Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll"()
Declare Sub ERPGetFingerprintImage Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll" (fingerprintimage As Byte(), ByRef tam_image As Integer)
Declare Sub ERPGetFingerprintTemplate Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll" (fingerprinttemplate As Byte(), ByRef tam_image As Integer)
Declare Sub ERPGetFingerprintBitMap Lib "C:\Desenv\EBioNet\EBioNet\Release\ERPDll.dll" (ingerprinttemplate As PictureBox, ByRef tam_image As Integer)
Dim buff() As Byte = New Byte(0) {}
Dim tam_image As Integer
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Call ERPInitialize(IntPtr.Zero)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call ERPStartCapture()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Call ERPIsFingerCaptured()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
tam_image = 256
ReDim buff(1000 * 1000)
Call ERPGetFingerprintImage(buff, tam_image)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Call ERPInitialize(PictureBox1.Handle.ToInt32)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Call ERPGetFingerprintTemplate(buff, tam_image)
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Call ERPGetFingerprintBitMap(PictureBox1, tam_image)
End Sub
End Class
VBAコードは以下の通りです:
Option Compare Database
Dim buff() As String
Dim tam_image As Integer
Private Declare Function ERPGetFingerprintImage Lib "C:\Biometria\ERPDll.dll" (ByRef fingerprintimage() As Byte, ByRef tam_image As Integer)
Private Sub Command2_Click()
On Error GoTo Command2_Click_erro
Dim buff() As Byte
tam_image = 256
ReDim buff(500000)
Call ERPGetFingerprintImage(buff, tam_image)
Command2_Click_exit:
Exit Sub
Command2_Click_erro:
MsgBox (Error & " - Rotina ERPGetFingerPrintImage e Rotina ERPGetFingerPrintTemplate")
End Sub
'fingerprintimage'を配列にするべきではありませんか? – Comintern
@Comintern次に、アンマネージコードは 'SAFEARRAY'構造体へのポインタを受け取ります。ごくまれにそれは実際にあなたが望むものですが、ほとんどの場合アンマネージドコードはメモリバッファへのポインタを期待しています。これはVB6/Aで、パラメータ 'byref as byte'を宣言し、バッファの最初のバイトを渡すことで実現されます。あるいは、パラメータ 'byval as long'を宣言し、' varptr(buf(lbound(buf))) 'を渡すこともできますが、それはあまり好きではありません。 – GSerg
意味があります。私はあなたがVBAコードで 'ERPGetFingerprintImage'を呼び出す方法を忘れていました。 – Comintern