It looks like I need a newer version of Windows.h that declares
IsWow64Process().
I can't get my program to compile with a call to this function (and
yes, I did try setting _WIN32_WINNT>=0x0501 WINVER>=0x0501). I've got
VC7 is the correct header file included somewhere or is there
someplace I can download it from?
OK, I was able to get things to compile by adding
-D_WIN32_WINNT=0x0501 to my makefile. Now there are other oddities
with calling IsWow64Process() from XP.
I'm running my program on XP and when it comes to the call to
IsWow64Process()an exception is thrown. Here's the code:
//begin C++ code:
typedef BOOL (*ISWOW64PROC) (HANDLE,PBOOL);
REGSAM CRegistry::check_64bit(REGSAM read_permissions)
{
ISWOW64PROC iswow64proc;
PBOOL is64bit = FALSE;
try {
iswow64proc= (ISWOW64PROC)
GetProcAddress(GetModuleHandle("KERNEL32\0"),"IsWow64Process\0");
//if(GetProcAddress(GetModuleHandle("kernel32\0"),"IsWow64Process\0")
!= NULL)
if(NULL != iswow64proc )
{
HANDLE this_process;
this_process = GetCurrentProcess();
printf("Do we get here? (we shouldn't on Win2k)\n");
if (this_process != NULL){
printf("this_process seems to be valid\n");
}else{
printf("this_process is NULL!\n");
}
//the offending call:
(iswow64proc)(this_process,is64bit);
printf("after call to iswow64proc\n");
if(*is64bit == TRUE)
{
read_permissions |= (KEY_WOW64_64KEY | KEY_WOW64_32KEY );
printf("...running on 64bit XP...\n");
}else{
printf("...running on 32bit XP...\n");
}
}else{
printf("...running on 32bit Windows (probably Win9*, Win2k,
WinME)...\n");
}
}
catch(...)
{
printf("...caught exception: probably running on 32bit
windows...\n");
return read_permissions;
}
return read_permissions;
}
//end of code
What happens on both XP 32 and 64bit is that it prints:
Do we get here? (we shouldn't on Win2k)
...caught exception: probably running on 32bit windows...
On Win2K it correctly determines that it cannot call IsWow64Process
and prints:
...running on 32bit Windows (probably Win9*, Win2k, WinME)...
Interestingly enough, I got this working initially in Ruby (using the
Win32API module).... Here's the (working) Ruby code (just the
relevant bits):
#begin Ruby code:
require 'Win32API'
module Win32
class Registry
module Constants
begin
IsWow64Process=Win32API.new("kernel32","IsWow64Process",['L','P'],'L')
rescue
puts "you're not on XP" if $DEBUG
isXP = false
else
puts "you're on XP: could be 32 or 64 bit" if $DEBUG
isXP = true
end
GetCurrentProcess =
Win32API.new("kernel32","GetCurrentProcess",[],'L')
<snip a lot of constants>
key_read = STANDARD_RIGHTS_READ |
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
if isXP
is64 = "\0" * 4
result = IsWow64Process.call(GetCurrentProcess.call(),is64)
is64 = is64.unpack("L")[0].to_i
if is64 > 0
puts "64bit XP" if $DEBUG
key_read |= (KEY_WOW64_64KEY | KEY_WOW64_32KEY )
else
puts "32bit XP" if $DEBUG
end
end
KEY_READ = key_read
<snip more non-relevant code>
end
end
end #of Ruby code
....The Ruby version works great, but I've got to get this working in
C++.
Any ideas?
Phil