26

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?

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
James Cadd
  • 12,136
  • 30
  • 85
  • 134

2 Answers2

37

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)
Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • 1
    It is misleading now, but it was originally named such to differentiate between 16 and 32 bit wasn't it? But they can hardly change the name, that'd break too many things... – Matthew Scharley Oct 08 '09 at 22:04
  • 1
    Yeah. I distinctly remember general protection faults caused by "USER.EXE" in Windows 3.1 in my childhood days. – Mehrdad Afshari Oct 08 '09 at 22:14
  • 3
    Gotta love how the System32 directory is still called that in 64 bit windows :-) – Justin Oct 08 '09 at 22:43
1

There is no user64.dll for the exact same reason you just described, .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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87