Determine the API of a 64-bit Operating System

Source: Internet
Author: User
Document directory
  • Syntax
  • Parameters
  • Return Value
  • Remarks
  • Examples
IsWow64Process Function

Determines whether the specified process is running under WOW64.

Syntax

BOOL WINAPI IsWow64Process(  __in   HANDLE hProcess,  __out  PBOOL Wow64Process);
Parameters
HProcess[In]

A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.

Windows Server 2003 and Windows XP:The handle must have the PROCESS_QUERY_INFORMATION access right.
Wow64Process[Out]

A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows, the value is set to FALSE. if the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.

Return Value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

Remarks

To compile an application that uses this function, define _ WIN32_WINNT as 0x0501 or later. For more information, see Using the Windows Headers.

Examples

For compatibility with operating systems that do not support this function, callGetProcAddressTo detect whetherIsWow64ProcessIs implemented in Kernel32.dll. IfGetProcAddressSucceeds, it is safe to call this function. otherwise, WOW64 is not present. note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function.

#include <windows.h>#include <tchar.h>typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);LPFN_ISWOW64PROCESS fnIsWow64Process;BOOL IsWow64(){    BOOL bIsWow64 = FALSE;    //IsWow64Process is not available on all supported versions of Windows.    //Use GetModuleHandle to get a handle to the DLL that contains the function    //and GetProcAddress to get a pointer to the function if available.    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");    if(NULL != fnIsWow64Process)    {        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))        {            //handle error        }    }    return bIsWow64;}int main( void ){    if(IsWow64())        _tprintf(TEXT("The process is running under WOW64./n"));    else        _tprintf(TEXT("The process is not running under WOW64./n"));    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.