Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 816
MilMike Avatar asked Feb 09 '10 14:02

MilMike


2 Answers

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)> _ 
like image 139
Anton Gogolev Avatar answered Sep 23 '22 22:09

Anton Gogolev


Imports System.Runtime.InteropServices 
like image 35
Luhmann Avatar answered Sep 21 '22 22:09

Luhmann