'JK講解 >> 法1. 重新命名宣告法 呼叫dll (VB6舊方法沿用過來)
'--------------------------------------
' 新宣告可以是同名
' Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindow" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
'同名還可以有 省略 寫法
'Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
'------------------------------------
'不同名寫法 (重新宣告新函數名 jkFindWindow) ( Alias 是指dll來源檔裡的函數名稱 FindWindow)
'Private Declare Auto Function jkFindWindow Lib "user32" Alias "FindWindow" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
'JK講解 >> 法2. 使用dll匯入類別作宣告 (新方法)
'要先匯入這個
Imports System.Runtime.InteropServices
'再重新宣告一次函數即可
' int QR_encode(int ecc_level, int len, const byte *data, const char *outputfile); '原本C++的dll 裡的宣告樣子
End Function
===========================================
EX:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim hWnd = FindWindow(vbNullString, "迅雷5") '找TITLE 是 此字串的視窗體
'Dim hWnd2 = FindWindow(vbNullString, "Debug")
MsgBox(hWnd, MsgBoxStyle.DefaultButton1, "title BBB")
'MsgBox(hWnd2, MsgBoxStyle.DefaultButton1, "title BB")
Const WM_CLOSE = &H10
SendMessage(hWnd, WM_CLOSE, 0, 0) '如果是執行檔 才有用
' My.Computer.Keyboard.SendKeys("{Enter}") '送出ENTER
End Sub