Get the App
SLTechnology News&Howtos  ›  Development  › 

How does VB.NET call Window API?

Shulou Source: shulou.com Published: 2022-06-02 09:04:01 10月08日 Update

This article mainly introduces how VB.NET calls Window API, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The way VB.NET calls Window API is similar to that in VB6, where you must use the declare statement to declare a reference to an external program in the dynamic link library (DLL). Let's make an example of the call and call the GetUserName function in advapi32.dll to get the user name of the system login.

Imports System

Imports System.Text

Imports Microsoft.VisualBasic

Public Class Form3Class Form3

Declare Function GetUsername () Function GetUsername Lib "advapi32.dll" Alias _

"GetUserNameA" (ByVal lpbuffer As String, ByRef nSize As Integer) _

As Integer

Private Sub Button3_Click () Sub Button3_Click (ByVal sender As System.Object

ByVal e As System.EventArgs) Handles Button3.Click

Dim RV As Integer

Dim UserName As String

Dim Buffer As String

Buffer = New String (CChar ("), 25)

RV = GetUsername (Buffer, 25)

UserName = Microsoft.VisualBasic.Left (Buffer, InStr (Buffer, Chr (0))-1)

MsgBox (UserName)

End Sub

End Class

Of course, DotNet FrameWork 2.0 already provides a rich set of class libraries. We can get almost all the functions without having to call Window API with VB.NET, especially after Microsoft's operating system is already set up on. Net FrameWork.

Thank you for reading this article carefully. I hope the article "how to call Window API with VB.NET" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles systems operating systems values interests functions functions dynamic simultaneously examples methods more friends users user names knowledge programs ribbons industries statements Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Apple MariaDB Docker