在.NET中使用API的方法 www.yescnet.com CNET中文網
可能說VB.NET是一個令人恨又令愛的編程軟件,新版的.NET不像VB6那樣多的支持API調用,好不容易在MSDN中找到的使用API的方法,代碼如下: [Visual Basic] SetLastError := True, CharSet := CharSet.Unicode, _ ExactSpelling := True, _ CallingConvention := CallingConvention.StdCall)> _ Public Shared Function MoveFile(src As String, dst As String) As Boolean ' Leave function empty - DLLImport attribute forces calls to MoveFile to ' be forwarded to MoveFileW in KERNEL32.DLL End Function 這是調用Kernel中的MoveFile函數(shù),在DllImport中必須聲明要調用的函數(shù)庫明,如Kernel32,User32,GDI32等,EntryPoint為要調用函數(shù)名. 下面是調用ShowWindow函數(shù)的實例: SetLastError:=True, CharSet:=CharSet.Unicode, _ ExactSpelling:=True, _ CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ShowWindow(ByVal HWNE As Integer,_ ByVal nCmdShow As Integer) As Integer
End Function 順便說一句,在.NET中使用從前VB6中HWND屬性的方法是: Me.Handle.ToInt32
|