Every time I see code calling into say kernel32.dll or User32.dll the snippet always, even on MSDN, requires the developer to hard code any required constants (WM_SETREDRAW = 11 for example) into the routine. Since these constants never change by definition and have one standard definition always, why doesn't .net provide them somewhere? I feel like we all end up creating our own libraries of constants and standard Windows dll calls as we need them. It seems like this duplication of effort is wasteful and prone to error.
Perhaps I haven't looked hard enough and they are all in there somewhere, if so could someone please provide their location?
Only the .Net team can provide the actual answer I think, we can only make assumptions.
There probably are many reasons. Here are some guesses:
IntPtr
objects), which is not the .Net-way of doing things (for instance you should use FileStream instead of CreateFile
/ReadFile
/WriteFile
/CloseHandle
)Environment.NewLine
for example (A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.
). So adding the whole Win32 API makes no sense.Microsoft added some Windows-specific classes in the Microsoft.Win32
namespace , but it's very limited and those functions are essential (registry operations, filedialogs...).
Concerning pinvoke.net, I wouldn't rely too much on it. I often see poorly written method declarations that would crash on x64 systems (int
instead of IntPtr
, struct layout issues...). Another example: the WriteFile
method declarations are inconsistent. SafeHandle
vs IntPtr
...etc.
There's not just a single reason, there are many. I can think of any of the following playing a role in the decision to not include them:
You can use the Pinvoke Interop Assistant tool. The declarations it provides are auto-generated from the Windows SDK headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With