declare

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章