Use WIN32 Function directly : DLL « Windows « VB.Net Tutorial






Option Strict On

Public Module Tester

   Public Declare Unicode Function MessageBox Lib "User32.dll" Alias "MessageBoxW" (ByVal hWnd As IntPtr, ByVal lpText As String, _
          byVal lpCaption As String, ByVal uType As UShort) As Short

   Private Declare Unicode Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryW" _
           (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer

   Private Const MB_OK As Integer = &H0&
   Private Const MAX_LEN As Integer = 256

   Public Sub Main()
      Dim caption As String = "System Directory"
      Dim message As String
      Dim buffer As String = Space(MAX_LEN)
      Dim retChars As Integer

      retChars = GetSystemDirectory(buffer, Len(buffer))
      message = Left(buffer, retChars)

      MessageBox(Nothing, message, caption, MB_OK)
   End Sub
End Module








24.1.DLL
24.1.1.Create DLL library
24.1.2.Use WIN32 Function directly