Windows API32位元VB ============================== ============================= Int, INT ByVal Long UNIT, DWORD ByVal Long BOOL ByVal Long ture时为1 WPARAM, LPARAM, LRESULT ByVal Long Handle(如HKEY) ByVal Long WORD, ATOM, SHORT ByVal Integer BYTE, CHAR ByVal Byte
Eg. ----------------------------------------------------------------------------- Windows API 宣告
SHORT GetKeyState( int nVirtKey )
对应的VB宣告
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer -----------------------------------------------------------------------------
----------------------------------------------------------------------------- Dim InsertMode as Integer InsertMode = GetKeyState(vbKeyInsert) And vbShiftMask If InsertMode = 1 then Debug.print "表示 Insert Mode" Else Debug.print "表示 OverWrite Mode" End If ----------------------------------------------------------------------------- 二、 指向整数的指标
Windows API 32位元VB ============================ ========================== LPINT (ByRef ) Long LPUNIT (ByRef ) Long LPBOOL (ByRef ) Long LPDWORD (ByRef ) Long LPHANDLE (如:PHKEY) (ByRef ) Long LPWORD (ByRef ) Integer LPSHORT (ByRef ) Integer LPBYTE (ByRef ) Byte
VB内定是使用传址呼叫,所以ByRef 可以省略,也就是说 Func(ByRef param1 as type) 与 Func(param1 as type) 是相同的,使用传址呼叫的方式,不外乎想将参数传给API 後将结果传回来。然而LONG 型态的传址呼叫在VB中又占了相当大的份量,因为32位元的指标都是LONG的型态,而字 串、自定型态的Structure在Windows API中是以指标来传递的,而指标的传递事实上也 是Long值的传递,只不过传过去的LONG值,於WIN API中会将之当成Address,而再配合 指标运作而得指标所指的内容,这个观念在後面会很重要。
例如: ----------------------------------------------------------------------------- LONG RegOpenKeyEx( HKEY hKey, // handle of open key LPCTSTR lpszSubKey, // address of name of subkey to open DWORD dwReserved, // reserved REGSAM samDesired, // security access mask PHKEY phkResult // address of handle of open key ); 相对应的VB 宣告 Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _ (ByVal hKey As Long, _ ByVal lpSubKey As String, _ ByVal ulOptions As Long, _ ByVal samDesired As Long, _ phkResult As Long) As Long ’//最後一个参数是ByRef之宣告 -----------------------------------------------------------------------------