blackhatmario blackhatmario -5 years ago 570 Question

How to use <DllImport> in VB.NET?

How should I DLLImport things in VB.NET? An example would be:

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer

End Function

If I put it inside a Class or somewhere else, I get "DLLimport is not defined" I am using Visual Studio 2008 Professional

Answer Source

You have to add Imports System.Runtime.InteropServices to the top of your source file.

Alternatively, you can fully qualify attribute name:

<System.Runtime.InteropService.DllImport("user32.dll", _
    SetLastError:=True, CharSet:=CharSet.Auto)> _
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download