VB 如何調用 c++ DLL?



```Class MainWindow

    'ByVal 值傳遞 ByRef 引用傳遞
    'Function 有返回值 Sub 無返回值
    'C語言數據類型在VisualBasic中聲明為調用時使用的表達式
    'ATOM ByVal variable As Integer 結果為Integer 類型的表達式
    'BOOL ByVal variable As Long 結果為 Long 類型的表達式
    'Byte ByVal variable As Byte 結果為 Byte 類型的表達式
    'Char ByVal variable As Byte 結果為 Byte 類型的表達式
    'COLORREF ByVal variable As Long 結果為 Long 類型的表達式
    'DWORD ByVal variable As Long 結果為 Long 類型的表達式
    'HWND, HDC, HMENU ByVal variable As Long 結果為 Long 類型的表達式等Windows 句柄
    'INT, UINT ByVal variable As Long 結果為 Long 類型的表達式
    'Long ByVal variable As Long 結果為 Long 類型的表達式
    'LPARAM ByVal variable As Long 結果為 Long 類型的表達式
    'LPDWORD variable As Long 結果為 Long 類型的表達式
    'LPINT, LPUINT variable As Long 結果為 Long 類型的表達式
    'LPRECT variable As Type 自定義類型的任意變量
    'LPSTR, LPCSTR ByVal variable As String 結果為 String 類型的表達式
    'LPVOID variable As Any 任何變量(在傳遞字符串的時候使用ByVal)
    'LPWORD variable As Integer 結果為Integer 類型的表達式
    'LRESULT ByVal variable As Long 結果為 Long 類型的表達式
    'NULL As Any 或 ByVal Nothing 或
    'ByVal variable As Long ByVal 0& 或 VBNullString
    'Short ByVal variable As Integer 結果為Integer 類型的表達式
    'VOID Sub procedure() 不可用
    'WORD ByVal variable As Integer 結果為Integer 類型的表達式
    'WPARAM ByVal variable As Long 結果為 Long 類型的表達式
    Private Declare Auto Function MSBox Lib "user32.dll" Alias "MessageBox" (ByVal hWnd As Integer, ByVal txt As String, ByVal caption As String, ByVal Typ As Integer) As Integer
    Private Declare Function VB_CreateOCRInstance Lib "CoCoOCR.dll" () As Long
    Private Declare Sub VB_ReleaseOCRInstance Lib "CoCoOCR.dll" ()

    Private Declare Function VB_Recognize Lib "CoCoOCR.dll" (ByVal filePath As String, ByVal result As String, ByVal len As Integer) As Integer
    Private Declare Function VB_RecognizeEx Lib "CoCoOCR.dll" (ByVal filePath As String, ByVal result As String, ByVal len As Integer, ByVal type As Integer) As Integer
    Private Declare Function VBRecognizeExEx Lib "CoCoOCR.dll" (ByVal filePath As String, ByVal result As String, ByVal len As Integer, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As Integer

    Const MB_ICONQUESTION As Integer = &H20
    Const MB_YESNO As Integer = &H4
    Const IDYES As Integer = 6
    Const IDNO As Integer = 7
    Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
        ' Stores the return value.
        Dim RetVal As Integer
        RetVal = MSBox(0, "Declare DLL Test", "Windows API MessageBox", MB_ICONQUESTION Or MB_YESNO)

        ' Check the return value.
        If RetVal = IDYES Then
            MsgBox("You chose Yes")
        Else
            MsgBox("You chose No")
        End If
    End Sub


    Private Sub button1_Click(sender As Object, e As RoutedEventArgs) Handles button1.Click
        Dim ret As Long
        Dim retRc As Integer
        ret = VB_CreateOCRInstance()

        If ret <> 0 Then
        Else
            Dim result As String = Space$(1024)
            Dim len As Integer = 1024
            Dim path As String = "D:\VisualStudio\Document_VS2015\CoCoOCR\Release\IMG_200WBS.jpg"
            retRc = VB_Recognize(path, result, len)
            textBox.Text = result
        End If
        VB_ReleaseOCRInstance();

    End Sub

    Private Sub button2_Click(sender As Object, e As RoutedEventArgs) Handles button2.Click

    End Sub
End Class


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM