From bddc0bee29a3f70057857bc20226d0929d46dbf7 Mon Sep 17 00:00:00 2001
From: Axel Gembe <ago@bastart.eu.org>
Date: Wed, 26 May 2010 09:38:46 +0200
Subject: [PATCH] fix wow64 registry mode on windows 2000

CMake fails to find any registry paths on Windows 2000 and according to regmon
it fails with an access denied error. I double checked all the access rights
and they are fine. After checking the access modes on MSDN I found that it says
KEY_WOW64_32KEY / KEY_WOW64_64KEY are not supported on Windows 2000. CMake does
not check if the current system supports Wow64 before applying these flags.

This patch adds a check for IsWow64Process in kernel32.dll before adding these
flags. Maybe this should be in a helper function, but I don't really know the
codebase well enough.

Signed-off-by: Axel Gembe <ago@bastart.eu.org>
---
 Source/kwsys/SystemTools.cxx |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index afc7240..7625e9a 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -565,6 +565,13 @@ void SystemTools::ReplaceString(kwsys_stl::string& source,
 static DWORD SystemToolsMakeRegistryMode(DWORD mode,
                                          SystemTools::KeyWOW64 view)
 {
+  // only add the modes when on a system that supports Wow64.
+  static void *wow64p = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
+  if(wow64p == NULL)
+    {
+    return mode;
+    }
+
   if(view == SystemTools::KeyWOW64_32)
     {
     return mode | KWSYS_ST_KEY_WOW64_32KEY;
-- 
1.5.6.5

