UINT uSize // size of directory buffer ); // 若成功,则传回目录的字元数 VB的宣告(API检视员) Declare Function GetWindowsDirectory Lib "kernel32" Alias _ "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) _ As Long 我们将之更改为 Declare Function GetWindowsDirectory Lib "kernel32" Alias _ "GetWindowsDirectoryA" ( lpBuffer As Byte, ByVal nSize As Long) As Long
----------------------------------------------------------------------------- 范例四 ***************************************************************************** Dim n as Long Dim Buff() as Byte Dim StrA as String
Buff = space(256) n=GetWindowsDirectory(Buff(0), 256) Buff = Leftb(Buff, n) StrA = StrConv(Buff, vbUniCode) 'StrA便是Windows所在目录 *****************************************************************************
在范例四中,GetWindowsDirectory()传入的第一个叁数Buff(0)便是这阵列的起始 Byte ,因VB 宣告成lpBuffer As Byte,故传过去的是ByRef Buff(0)的位址,当然了 ,你也可以呼叫成n=GetWindowsDirectory(Buff(1), 256),只是传回值是填在Buff(1) to Buff(n),而Buff(0)则仍为起始的Space Character(32),因为该API传回值是字 元个数,再加上存於Buff中的是Byte Array故,使用Leftb()去除多出的byte,再用 StrConv将Byte Array转成Unicode的字串。比照范例二的作法,我们也可以将Byte Array 改成以String的方式来做,二者可做一比较,谁比较好或比较顺畅,那见人见智 ,不过可以肯定的是,如果传的值是Binary的值,那麽使用Byte Array来做才对,因用 String来传的话,会经过转换成UniCode的步骤,这中间会发生什麽事,没人知道。
六、CallBack Function的作法
VB的使用者通常对於这个名词有着多多少少的疑惑,或称之为"哭爸"Function,而 VB5使用手册使用Window Procedure来说明,除非对Window 系统有一些了解,否则可能 令人更不知所云;我使用另一个例子来说明,那便是KeyBoard Hook。什麽是KeyBoard Hook 呢,简言之便是按键盘时,便会自动执行某一段Function的功能,就好比Dos时代 的拦截中断向量一般。让我们先看一下设定Hook的宣告吧。
----------------------------------------------------------------------------- HHOOK SetWindowsHookEx( int idHook, // type of hook to install HOOKPROC hkprc, // address of hook procedure HINSTANCE hMod, // handle of application instance DWORD dwThreadID // identity of thread to install hook for );
Declare Function SetWindowsHookEx Lib "user32" Alias SetWindowsHookExA" _ (ByVal idHook As Long, 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] 下一页
|