Is there a complete user32.dll shell library available for .NET?

I am doing a lot of interop for user32.dll at the moment through VB.NET. Since user32.dll is not at the .NET level, but at its own level, I need to declare functions using the Declare statement. Although this works great, I keep declaring them again and again.

I was googling around, but the only useful site I came across was pinvoke.net . Although it contains information to a certain extent, there are many functions that are either not described or that contain many parts of TODO in its documentation.

So I was wondering if the full shell for user32.dll for .NET exists. I couldn’t find anyone I’m afraid of, but maybe I don’t look right.

+6
windows winapi pinvoke
source share
4 answers

A complete shell for user32.dll for the .NET Framework would be completely pointless. The vast majority of functions exported by user32.dll have corresponding functions that were originally implemented by the .NET Framework. In fact, the entire .NET Framework is just a wrapper around the Windows API, including user32.dll.

I recommend that you do not try to execute the P / Invoke functions from user32.dll when there is a way to do this through managed code using functions already provided by the .NET Framework. Check the MSDN or the handy .NET reference guide of your choice for this before attempting to invent the wheel yourself.

If and when you determine that certain functions (s) that you need do not have a native equivalent, then and only then you should consider the P / Call Windows API. In this case, since you have significantly narrowed the scope of functions that you must import, only minimal work should be used to determine the function signature, using a combination of MSDN documentation, pinvoke.net and a stack overflow. I would say that you yourself wrote this code (now that you have reduced what you need to a more manageable size), you need to read the documentation and understand exactly how it works. If you rely on code written by someone else, there is no guarantee that it is written correctly, that it follows best practices, that it implements any error handling, or even understands how it works and how to use it.

Finally, I recommend that even in VB.NET you use the standard C # syntax for P / Invoking functions, not Declare . For example:

 <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _ Private Shared Function AppendMenu(ByVal hMenu As IntPtr, ByVal uFlags As MenuFlags, ByVal uIDNewItem As Int32, ByVal lpNewItem As String) As Boolean End Function 

There are several reasons why I think this is preferable:

  • The Declare syntax is an attempt to maintain backward compatibility with VB 6. The official .NET method (commonly used in C #) uses the <DllImport> attribute, and since you are writing new code that targets the .NET Framework, you should seriously consider using the official syntax . Another advantage here is that your code will be more familiar to people who use C #, and they will be able to help you more in your ads. Samples that you find on the Internet are likely to be written this way, instead of using the outdated VB 6 syntax.

  • Sometimes Declare syntax has some unexpected behavior. For example, some types are sorted differently than the standard <DllImport> syntax. This can be quite confusing for people who are more familiar with standard .NET behavior.

Also see this question on a similar issue.

+5
source share

There are several automatic P / Invoke signature generators that can help you.

+1
source share

I would just use a prebuilt wrapper called "Managed Windows API" . It does not have everything, but it has everything. When using the Visual Studio Add-in in PInvoke.net , you should have a pretty automatic way to solve this problem.

+1
source share

I hope the following url helps you.

http://mwinapi.sourceforge.net/

0
source share

All Articles