if (Is64bitSystem)
{
hlibrary = LoadLibrary(_T("Kernel32.dll"));
if( !Wow64DisableWow64FsRedirection(&OldValue) )
{
exit(0);
}
}
只是部分,想问下,如果我在代码中加判定,想实现只在64位系统中(例如win7 x64)才执行if中的语句。
可行么?想release的是32位exe
16 个解决方案
#1
调用GetSystemInfo
会返给你一个SYSTEM_INFO结构
结构里
wProcessorArchitecture代表cpu架构,0是x86,9是x64
会返给你一个SYSTEM_INFO结构
结构里
wProcessorArchitecture代表cpu架构,0是x86,9是x64
#2
Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").IndexOf("64") != -1
如果为true则是64位的。
如果为true则是64位的。
#3
BOOL Is64bitSystem()
{
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
}
用这个判断,release 的exe是32位的 在win7 x64运行没有问题在xp 32运行会失败 还是会跑到if里面去
出错dll加载失败。
#4
GetNativeSystemInfo Function
发送反馈
Retrieves information about the current system to an application running under WOW64. If the function is called from a 64-bit application, it is equivalent to the GetSystemInfo function.
别用这个,用GetSystemInfo
发送反馈
Retrieves information about the current system to an application running under WOW64. If the function is called from a 64-bit application, it is equivalent to the GetSystemInfo function.
别用这个,用GetSystemInfo
#5
Is64bitSystem = sizeof(int)==4?false:true;
#6
这个没用。int大小其实似乎编译是决定的。指针大小这些都是编译时定下的。
#7
没用的……VC无论x86还是x64,int、long都是4字节
#8
呵呵,编译就决定了。。嗯嗯,
学习了,谢谢
学习了,谢谢
#9
GetSystemInfo 也不行。 是什么地方错了? 我release的是32位的exe。
#10
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
#if __WORDSIZE == 64
#else
#endif
#11
# cat /etc/SuSE-release
SUSE LINUX Enterprise Server 9 (i586)
VERSION = 9
PATCHLEVEL = 2
# gdb
GNU gdb 6.3
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
(gdb)
////////////////////////
# cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 1
# gdb int
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 8
我发现一个很有意思的现象,估计是gdb的bug?
如果64位操作系统不gdb 应用程序,直接gdb,结果如下:
# gdb
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
#12
只能通过api.
#13
SYSTEM_INFO si;
GetSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
或是
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
GetSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
或是
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
#14
学习了
#15
http://social.msdn.microsoft.com/Forums/zh-CN/windowsgeneraldevelopmentissues/thread/aa8a3372-b2cf-4024-a2b7-af9cec3b738b
#16
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
if(NULL != fnIsWow64Process)
{
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
printf("执行fnIsWow64Process失败!\n");
}
}
return bIsWow64;
}
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
if(NULL != fnIsWow64Process)
{
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
printf("执行fnIsWow64Process失败!\n");
}
}
return bIsWow64;
}
#1
调用GetSystemInfo
会返给你一个SYSTEM_INFO结构
结构里
wProcessorArchitecture代表cpu架构,0是x86,9是x64
会返给你一个SYSTEM_INFO结构
结构里
wProcessorArchitecture代表cpu架构,0是x86,9是x64
#2
Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").IndexOf("64") != -1
如果为true则是64位的。
如果为true则是64位的。
#3
BOOL Is64bitSystem()
{
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
}
用这个判断,release 的exe是32位的 在win7 x64运行没有问题在xp 32运行会失败 还是会跑到if里面去
出错dll加载失败。
#4
GetNativeSystemInfo Function
发送反馈
Retrieves information about the current system to an application running under WOW64. If the function is called from a 64-bit application, it is equivalent to the GetSystemInfo function.
别用这个,用GetSystemInfo
发送反馈
Retrieves information about the current system to an application running under WOW64. If the function is called from a 64-bit application, it is equivalent to the GetSystemInfo function.
别用这个,用GetSystemInfo
#5
Is64bitSystem = sizeof(int)==4?false:true;
#6
这个没用。int大小其实似乎编译是决定的。指针大小这些都是编译时定下的。
#7
没用的……VC无论x86还是x64,int、long都是4字节
#8
呵呵,编译就决定了。。嗯嗯,
学习了,谢谢
学习了,谢谢
#9
GetSystemInfo 也不行。 是什么地方错了? 我release的是32位的exe。
#10
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
#if __WORDSIZE == 64
#else
#endif
#11
# cat /etc/SuSE-release
SUSE LINUX Enterprise Server 9 (i586)
VERSION = 9
PATCHLEVEL = 2
# gdb
GNU gdb 6.3
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
(gdb)
////////////////////////
# cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 1
# gdb int
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 8
我发现一个很有意思的现象,估计是gdb的bug?
如果64位操作系统不gdb 应用程序,直接gdb,结果如下:
# gdb
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
#12
只能通过api.
#13
SYSTEM_INFO si;
GetSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
或是
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
GetSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
else
{
return FALSE;
}
或是
if (sizeof(long) != sizeof(int))
{
//64bit
}
else
{
//32bit
}
#14
学习了
#15
http://social.msdn.microsoft.com/Forums/zh-CN/windowsgeneraldevelopmentissues/thread/aa8a3372-b2cf-4024-a2b7-af9cec3b738b
#16
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
if(NULL != fnIsWow64Process)
{
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
printf("执行fnIsWow64Process失败!\n");
}
}
return bIsWow64;
}
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
if(NULL != fnIsWow64Process)
{
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
printf("执行fnIsWow64Process失败!\n");
}
}
return bIsWow64;
}