joseph taylor
joseph taylor

Reputation: 123

Is user32.dll the "WinApi" msdn speaks of?

In the following code,

using System.Runtime.InteropServices;
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

I googled the "mouse_event" function of user32.dll, and got this. Is importing user32.dll the equivalent of referencing the Win32 API, making said documentation a valid resource for info of other functions and their parameters? And why is it that a "user32.dll" would in "c# bear the function names of what is consistently referred to elsewhere as "WINAPI" or "WIN32"?

Upvotes: 1

Views: 2958

Answers (1)

PMF
PMF

Reputation: 17248

What Microsoft calls the "Win32 API" is the interface to the windows operating system. Any interaction with the OS (creating windows, opening files, accessing network etc.) needs to go trough any of these well documented function calls. Many C# functions are behind the scenes actually wrapper implementations for these operating system functions. Some of the more specific methods do not have C# equivalents though, and you can use code as the one you presented (using the [DllImport] attribute) to access them anyway.

The Win32 API for legacy reasons primarily consists of three files: kernel32.dll (file io/synchronisations) gdi32.dll (user interface) and user32.dll (more user interface). These three libraries include almost all the functions that make up that API. Other libraries where added over time and are used for specific purposes.

(Note: The dll's themselves don't do much any more. In current implementations, they're just wrappers around other libraries, but from an application point of view, that doesn't matter)

Upvotes: 3

Related Questions