0

I need to detect if the app is running on Win32/64.

Update: People are reporting that relying on the [HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0] key is not a good idea.

Community
  • 1
  • 1
Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • That code is pretty gnarly. `LoadLibrary` returns an `HMODULE`. `GetModuleHandle('kernel32')` would be better than `LoadLibrary`. Dodgy use of `@`. Pointless initialisation of `vIsWow64`. Seems hard to believe that `IsWow64Process` would return `True` on a 32 bit OS. – David Heffernan Mar 16 '15 at 10:42
  • 1
    @TLama The code in the question calls `IsWow64Process`. It doesn't just detect whether or not the function is exported. – David Heffernan Mar 16 '15 at 10:43
  • @Altar I cannot reproduce. Your function, with its wrinkles, returns false on my 32 bit xp system. Note that I added diagnostics to prove that it reached the call to `IsWow64Process` and that call succeeded (returned true). I find it pretty hard to believe that `IsWow64Process` does not work. – David Heffernan Mar 16 '15 at 10:48
  • The main thing is that I wanted you to notice `TOSVersion.Architecture` before moving on with your code. You can remove the code in your question and just use `TOSVersion.Architecture`. – David Heffernan Mar 16 '15 at 10:59
  • @user246408 Serg, the dupe that you closed this for asks about D2007, which rather rules out `TOSVersion` answers. The question here is XE7. – David Heffernan Mar 16 '15 at 11:45
  • @DavidHeffernan Sorry these questions are very close and I wanted to link them; did not know that voting for close as duplicate works this way now. – kludg Mar 16 '15 at 15:32
  • @user246408 I would simply paste a link into a comment. Like this: *Related: http://stackoverflow.com/questions/2523957/how-to-get-information-about-the-computer-32bit-or-64bit* – David Heffernan Mar 16 '15 at 15:54

1 Answers1

9

The code that you present in the question has a few wrinkles, but it does work correctly. I suspect that you are not actually running that code, and have made an error and somehow posted the wrong code.

FWIW, you should use TOSVersion from System.SysUtils to check the bitness of the underlying platform. The TOSVersion.Architecture property will tell you whether or not the underlying platform is 32 or 64 bit.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    Even that's quite hard nowadays given that `GetVersionEx` lies! Still, `TOSVersion` does give you version numbers and a name so I guess it gets a good way there, modulo the `GetVersionEx` thing. – David Heffernan Mar 16 '15 at 11:09