Question

There are many Win32 API calls / libraries like kernel32 or shell32 that may be usefull to call from C#. A common method of using them is looking up the method definition on the pinvoke.net website, and using the dllimport definition from there.

This process is required for every method you wish to use.

Are there assemblies availble that contain common / most [DllImport]ed API functions?

I'm looking for something i can use directly from C# (as a reference), so i don't have to gather and combine all kinds of DLLImport statements myself (with risk of errors).

Was it helpful?

Solution

That I know of, there is no widely known bundle of code wrapping the Windows API for .NET; I could see it being useful in certain circumstances, however, in most cases, if you need to use so much of the native Windows API then you should maybe ask yourself whether or not you're utilising the .NET framework properly and/or why use .NET at all?

Regardless of the above opinion, you can find a pretty comprehensive source of the definitions at http://pinvoke.net/.

OTHER TIPS

You should find here at pinvoke.net what you are looking for. There's actually nothing more “behind the scenes” that could be shipped in C# source code than plain simple DLL import clauses.

That's not the way it works, you only provide the [DllImport] declaration in your C# code. Just the way you'd find them on pinvoke.net or a tool like the P/Invoke Interop Assistant. Finding out how to actually use the API function requires studying C or C++ code. And in general understanding how the Windows API works.

The best place to get started with that is Petzold's seminal book "Programming Windows". You can find source code samples in C/C++ in the Windows SDK documentation and the many samples that are included with the full version of the SDK. And the web of course, just by searching for the function name. Somewhat ironically, the number of samples you'd find on the web these days that are written in a managed language start to out-number the C/C++ samples. Beware of VB6 declarations (Declare keyword), also widely available, its types are not compatible with .NET.

Sites like codeplex.com and codeproject.com are a good place to find libraries with managed class wrappers around native API calls. You'd normally simply use the library.

Last but not least, stackoverflow.com is an excellent resource ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top