declare

来源:互联网 发布:方维app.js 编辑:程序博客网 时间:2024/05/16 08:39

http://blog.csdn.net/jacky01130/article/details/2601696

1.语法

VB里的说明语句(Declare),仅支持动态链结库(DLL)的子程序和无变量函数。

VB程序要使用DLL中的函数,首先必须要有特殊的声明,用Declare声明语句在窗体级或模块级或全局模块的代码声明段进行声明,将动态链接库中的函数声明到VB中,供VB程序调用。

语句格式为:

Declare Sub 过程名 Lib [ Alias " 别名] ([ByVal 参数 AS 类型]),

Declare Function 函数名 Lib [Alias " 别名]([ByVal 参数 AS 类型]) AS 类型

在声明中首先用Declare关键字表示声明DLL中的函数。

2.例子

(1)sub例子

Private Declare Sub WTSFreeMemory _    

        Lib "wtsapi32.dll" _    

(ByVal pMemory As Long)

(2)function例子

Private Declare Function WTSQuerySessionInformation _    

         Lib "wtsapi32.dll" Alias "WTSQuerySessionInformationA" _    

        (ByVal hServer As Long, _     

         ByVal SessionId As Long, _   

         ByVal WTSInfoClass As WTS_INFO_CLASS, _     

        ByRef ppBuffer As Long, _     

       ByRef pBytesReturned As Long) _

As Long

0 0