How to: Call Windows APIs (Visual Basic)
This example defines and calls the MessageBox
function in user32.dll and then passes a string to it.
Example
' Defines the MessageBox function.
Public Class Win32
Declare Auto Function MessageBox Lib "user32.dll" (
ByVal hWnd As Integer, ByVal txt As String,
ByVal caption As String, ByVal Type As Integer
) As Integer
End Class
' Calls the MessageBox function.
Public Class DemoMessageBox
Public Shared Sub Main()
Win32.MessageBox(0, "Here's a MessageBox", "Platform Invoke Sample", 0)
End Sub
End Class
Compile the code
This example requires:
- A reference to the System namespace.
Robust Programming
The following conditions may cause an exception:
The method is not static, is abstract, or has been previously defined. The parent type is an interface, or the length of name or dllName is zero. (ArgumentException)
The name or dllName is
Nothing
. (ArgumentNullException)The containing type has been previously created using
CreateType
. (InvalidOperationException)
See also
Spolupráca s nami v službe GitHub
Zdroj tohto obsahu nájdete v službe GitHub, kde môžete vytvárať a skúmať problémy a žiadosti o prijatie zmien. Ďalšie informácie nájdete v našom sprievodcovi prispievateľom.
Pripomienky
https://aka.ms/ContentUserFeedback.
Pripravujeme: V priebehu roka 2024 postupne zrušíme službu Problémy v službe GitHub ako mechanizmus pripomienok týkajúcich sa obsahu a nahradíme ju novým systémom pripomienok. Ďalšie informácie nájdete na stránke:Odoslať a zobraziť pripomienky pre