Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically pull in Win32 API declarations in C#?

Tags:

c#

winapi

I am searching for a way that will automate adding declarations of Win32 API functions in C# code. For example, I currently have to add:

[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string path);

when I want to call LoadLibrary. And similar for every other function that I want to call.

Is there some list of all these Win32 declarations already so that I don't have to keep adding them myself? Or some other "correct" way of doing this?

like image 498
Zabba Avatar asked Oct 30 '11 00:10

Zabba


2 Answers

Look into PInvoke.net and its Visual Studio plugin.

like image 163
Teoman Soygul Avatar answered Oct 05 '22 23:10

Teoman Soygul


On the site http://pinvoke.net/ you can find a free plugin for Visual Studio for adding pinvoke signatures.

like image 26
Patrick Avatar answered Oct 06 '22 01:10

Patrick