Declare Function GetTickCount Lib "kernel32" Alias
_ "GetTickCount" () As Long 对于其它 DLL,Lib 子句指定文件的路径:
Declare
Function lzCopy Lib "c:\windows\lzexpand.API" _ (ByVal S As Integer, ByVal D
As Integer) As Long 如果未指定 libname 的路径,Visual Basic 将按照下列顺序查找该文件:
.exe 文件所在的目录
当前目录
Windows 位系统目录(通常为
\Windows\System)
Windows 目录(不一定是 \Windows)
Path
环境变量中的目录
二.处理使用字符串的 Windows API 过程
如果调用的 Windows API
过程要使用字符串,那么声明语句中必须增加一个 Alias 子句,以指定正确的字符集。包含字符串的 Windows API 函数实际有两种格式:ANSI 和
Unicode。因此,在 Windows 头文件中,每个包含字符串的函数都同时有 ANSI 版本和 Unicode 版本。 例如,下面是
SetWindowText 函数的两种 C 语言描述。可以看到,第一个描述将函数定义为 SetWindowTextA,尾部的“A”表明它是一个 ANSI
函数:
因为两个函数实际的名称都不是“SetWindowText”,要引用正确的函数就必须增加一个 Alias
子句:
Private Declare Function SetWindowText Lib "user32" _ Alias
"SetWindowTextA" (ByVal hwnd As Long, ByVal _ lpString As String) As
Long
请注意,Alias 子句后面的字符串必须是过程的真正名称,而且必须是区分大小写的。 对于 Visual Basic
中使用的 API 函数,应该指定函数的 ANSI 版本,因为只有 Windows NT 才支持 Unicode 版本,而 Windows 95
不支持这个版本。仅当应用程序只运行在 Windows NT 平台上的时候才可以使用 Unicode
版本。