C# 在 64 位系统上调用 user32.dll

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1540741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:37:40  来源:igfitidea点击:

C# PInvoking user32.dll on a 64 bit system

c#64-bitpinvoke32-bituser32

提问by James Cadd

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?

在 64 位 Windows 上从 64 位应用程序 pinvoke user32.dll 是错误的吗?我已经成功地完成了多次并且从未出现过错误,但这似乎是矛盾的。我应该查找 user64.dll 吗?

采纳答案by Mehrdad Afshari

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

这个名字user32.dll有误导性。这是user32.dll您正在调用的 64 位版本。64 位版本位于%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 dumpbinutility:

包含 32 位版本以兼容 32 位应用程序。它位于%windir%\SysWOW64\user32.dll。您可以使用该dumpbin实用程序检查它们:

System32\user32.dll:

System32\user32.dll:

FILE HEADER VALUES
        8664 machine (x64)

SysWOW64\user32.dll:

SysWOW64\user32.dll:

FILE HEADER VALUES
         14C machine (x86)

回答by Shay Erlichmen

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.

没有 user64.dll 与您刚刚描述的原因完全相同,.net 程序可能与 cpu 架构无关,因此相同的代码需要在 x86 和 x64 上运行。
如果你把你的程序带到 x86 平台,它仍然可以运行,无需任何修改。
我猜当他们命名 user32.dll 时,他们并没有考虑到这些情况。