C# PInvoking user32.dll on a 64 bit system

守給你的承諾、 提交于 2019-11-29 10:54:27

问题


Is it wrong to pinvoke user32.dll on 64 bit Windows, from a 64 bit app? I've done this successfully a number of times and never had an error, but it seems contradictory. Should I look for user64.dll instead?


回答1:


The name user32.dll is misleading. It's the 64 bit version of user32.dll you're calling. The 64 bit version is located at %windir%\System32\user32.dll.

A 32-bit version is included for compatibility with 32-bit applications. It's located at %windir%\SysWOW64\user32.dll. You can inspect them using the dumpbin utility:

System32\user32.dll:

FILE HEADER VALUES
        8664 machine (x64)

SysWOW64\user32.dll:

FILE HEADER VALUES
         14C machine (x86)



回答2:


There is no user64.dll for the exact same reason you just describe, .net program can be agnostic to cpu architecture so the same code needs to work on x86 and x64.
If you take your program to x86 platform it will still run without any modifications.
I guess that when they named user32.dll they didn't have those scenarios in mind.



来源:https://stackoverflow.com/questions/1540741/c-sharp-pinvoking-user32-dll-on-a-64-bit-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!