與vb6.0的語法一樣啊
10年的常寧網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整常寧建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“常寧網(wǎng)站設(shè)計(jì)”,“常寧網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
Private Declare Function 函數(shù)名 Lib "庫名" Alias "別名" (形參1 As 類型,形參2 As 類型,形參3 As 類型,形參4 As 類型,形參5 As 類型) As 返回值類型
success = WritePrivateProfileStringA改成success = WritePrivateProfileString 另外vc6里的long在vc.net里要換成integer,你這樣調(diào)用會(huì)出錯(cuò)的
Public Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowText" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As Integer) As Integer
Public Function GetText(ByVal hwnd As Integer) As String
Dim nLen As Integer
nLen = GetWindowTextLength(hwnd)
GetText = Space(nLen)
GetWindowText(hwnd, GetText, nLen)
End Function
VS2008測試通過, 函數(shù)GetText傳入的就是對應(yīng)文本框的句柄.
不會(huì)這個(gè)API,不過提醒下,.net的API聲明類型都為Integer,不是Long
(1).使用DllImport特征類來申明Windows API函數(shù):
下面是在Visual Basic .Net中使用DllImport特征類申明二個(gè)Windows API函數(shù)的具體示例:
'函數(shù)ExtractIcon,其功能是是從指定文件的指定位置導(dǎo)出圖標(biāo)的Windows句柄。
< System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint := "ExtractIcon" ) > _
Public Function _
ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
End Function
'函數(shù)Icon_Num,其功能是獲得指定文件中的圖標(biāo)數(shù)目
< System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint := "ExtractIcon" ) > _
Public Function _
Icon_Num ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer
End Function
在使用DllImport特征類申明Windows API函數(shù)時(shí),如果申明的函數(shù)名稱和函數(shù)的入口點(diǎn)相同,則可以在申明Windows API函數(shù)時(shí),省略定義函數(shù)入口點(diǎn)對應(yīng)的代碼,即EntryPoint對象字段對應(yīng)的代碼,這樣聲明ExtractIcon函數(shù)的代碼也可以簡化為如下所示:
< System.Runtime.InteropServices.DllImport ( "Shell32.dll" ) > _
Public Function _
ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
End Function
(2).使用“Declare”語句來申明Windows API函數(shù):
使用“Declare”語句的確比使用DllImport特征類要簡單了許多,下面是在Visual Basic .Net中使用“Declare”語句來聲明上述二個(gè)Windows API函數(shù)的具體方法:
Declare Auto Function ExtractIcon Lib "Shell32.dll" Alias "ExtractIcon" ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
'聲明ExtractIcon函數(shù)
Declare Auto Function Icon_Num Lib "Shell32.dll" Alias "ExtractIcon" ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer
'聲明Icon_Num函數(shù)
在Visual Basic .Net中聲明Windows API函數(shù)時(shí),“Declare”語句中Alias關(guān)鍵字的作用相當(dāng)于使用DllImport特征類中的EntryPoint對象字段。同樣在使用“Declare”語句聲明Windows API函數(shù)時(shí),如果聲明的函數(shù)和函數(shù)的入口點(diǎn)相同,也可以省略Alias關(guān)鍵字對應(yīng)的代碼,所以ExtractIcon函數(shù)也可以簡化為如下:
Declare Auto Function ExtractIcon Lib "Shell32.dll" ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr