Checking for a Windows 64-bit

Checking for a Windows 64-bit

Postby driessen » Tue Jun 29, 2010 9:09 am

Hello,

How can we check in FWH if an application is running on a 64-bit Windows version ?

Thanks you very much in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking for a Windows 64-bit

Postby Antonio Linares » Tue Jun 29, 2010 9:32 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Checking for a Windows 64-bit

Postby Davide » Fri Aug 13, 2010 1:29 am

Antonio,

I found out that IsWin64() doesn't work on Windows 7 professional 64bit (6.1 build 7600 - it returns .f.)

I'm still on FWH 9.05 - xH 1.2.1 - bcc 5.5 - Is this the problem ?

Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: Checking for a Windows 64-bit

Postby Davide » Fri Aug 13, 2010 11:08 pm

Simple test:

Image

Nobody's using IsWin64() here ?

Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: Checking for a Windows 64-bit

Postby Davide » Sat Aug 14, 2010 1:09 am

Hi guys,

here's the function, taken from http://msdn.microsoft.com/en-us/library ... 85%29.aspx

I tested in:
Windows 98 -> .F.
WinXP 32 SP3 -> .F.
Vista 32 SP2 -> .F.
Win7 64 -> .T.

Could you please check if I made the right corrections for xH and test it against your own 32/64 bit Windows ?

Thanks,
Davide


Code: Select all  Expand view
#include "Fivewin.ch"

FUNCTION MAIN()

? IsWow64()

RETURN NIL

//---------------------------------------------------------------------------

#pragma BEGINDUMP

#include <windows.h>
#include <stdio.h>

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

HB_FUNC( 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
        }
    }
    hb_retl( bIsWow64 );
    return; // bIsWow64;
}

#pragma ENDDUMP

//---------------------------------------------------------------------------
 
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: Checking for a Windows 64-bit

Postby Daniel Garcia-Gil » Sun Aug 15, 2010 6:27 pm

Davide...

Yes, your purpose is correct, but if the application was built under 32 bits, for correct this function we changed source\winapi\wndis.c
with this change applications built under 32 and 64 will show .T.

Thanks...

Code: Select all  Expand view

#ifdef _WIN64
HB_FUNC( ISWIN64 ) // Check if Windows 64 is running
{
   hb_retl( ( sizeof( void * ) == 8 ) );
}      
#else
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

HB_FUNC( ISWIN64 )
{
    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( "kernel32") ,"IsWow64Process");
    if(NULL != fnIsWow64Process)
    {
       !fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
    }
    hb_retl( bIsWow64 );
}
#endif /*_WIN64*/
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Checking for a Windows 64-bit

Postby Davide » Mon Aug 16, 2010 9:07 am

Daniel,

thank you for your feedback.
Daniel Garcia-Gil wrote:HB_FUNC( ISWIN64 )

I intentionally left IsWin64() untouched and added IsWow64() because the former is already used (for example) in rPreview.prg to determine whether to load the 32 or 64 bit DLL. Your change would make a FWH32 program trying to load PREV64.DLL (that's not possible)

Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: Checking for a Windows 64-bit

Postby Daniel Garcia-Gil » Mon Aug 16, 2010 10:52 am

Davide wrote:Daniel,

thank you for your feedback.
Daniel Garcia-Gil wrote:HB_FUNC( ISWIN64 )

I intentionally left IsWin64() untouched and added IsWow64() because the former is already used (for example) in rPreview.prg to determine whether to load the 32 or 64 bit DLL. Your change would make a FWH32 program trying to load PREV64.DLL (that's not possible)

Hi,
Davide


Yes is correct
Now for clear facts...
The function IsWin64 return .T. / .F. if the application was built under 64
Function IsWow64 return .T. / .F. if the application was built in 32bit and run over 64

Code: Select all  Expand view

HB_FUNC( ISWIN64 ) // Check if Windows 64 is running
{
   hb_retl( ( sizeof( void * ) == 8 ) );
}      


typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

HB_FUNC( 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( "kernel32") ,"IsWow64Process");
    if(NULL != fnIsWow64Process)
    {
       fnIsWow64Process(GetCurrentProcess(),&bIsWow64);
    }
    hb_retl( bIsWow64 );
}
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Checking for a Windows 64-bit

Postby Davide » Tue Aug 17, 2010 1:05 am

Daniel,
Daniel Garcia-Gil wrote:The function IsWin64 return .T. / .F. if the application was built under 64
Function IsWow64 return .T. / .F. if the application was built in 32bit and run over 64

Code: Select all  Expand view

HB_FUNC( ISWIN64 ) // Check if Windows 64 is running
 


Yes. I believe that the comment should be:
HB_FUNC( ISWIN64 ) // Check if my program is a 64 bit one (useful if you're using either FWH32 or FWH64)
Obviously if it's .T. you're evidently using Windows64 bit, but a FWH32 program will always return .F. even on Win64 (that's why I added IsWow64)

The Wiki about IsWin64() should explain that too.

Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: Checking for a Windows 64-bit

Postby Daniel Garcia-Gil » Tue Aug 17, 2010 1:50 am

Davide...

http://wiki.fivetechsoft.com/doku.php?i ... on_iswin64
This function returns .t. if we are executing the application under Windows 64 bit
i saw the wiki and explain is wrong and correct

IsWin64 return .T. / .F. if the program was built with 64 bit complier (no need emulation for run), and you're right
Davide wrote:Obviously if it's .T. you're evidently using Windows64 bit, but a FWH32 program will always return .F. even on Win64 (that's why I added IsWow64)

this is expect return value
Download samples 32bit

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows
for this reason IsWow64 return .T. when run in 64bit a program built in 32 bits, because only work with 32bit programs
Download samples 64bit
Code: Select all  Expand view

#include "Fivewin.ch"

FUNCTION MAIN()

? "Is Windows 64 (IsWin64):" + cValToStr( IsWin64() ), "Is Windows 64 (IsWow64):" + cValToStr( IsWow64() )

RETURN NIL
 


Obviously is a program built in 64bit is running, is in 64 bit OS
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Checking for a Windows 64-bit

Postby StefanHaupt » Tue Aug 17, 2010 7:54 am

Daniel,

maybe the name of the function is a little bit confusing. The other funcions (IsWinXP(),...) are returning the version of the OS, so I think it would be clearer if IsWin64() would return the type of the OS (.f. for 32bit and .t. for a 64bit OS).

I suggest IsWin64() for the OS and IsWow64() for the application. IsWin64() should return .t. if a 64bit OS is running, IsWow64() should return .t. if a 32bit app is running under 64bit.

Just an idea...
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Checking for a Windows 64-bit

Postby Daniel Garcia-Gil » Tue Aug 17, 2010 10:51 am

Stefan...

the return value is correct in both case
the point is call IsWin64 in 32 bit program (built) never shall return .T. because run in emulation mode (WOW64) under 64 bit OS, this emulation is 32bits
like say : http://msdn.microsoft.com/en-us/library/ms684139(VS.85).aspx
IsWow64 Determines whether the specified process is running under WOW64.
i mean, no verify OS verify emulation mode
so we need use IsWow64 in 32bit applications
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Checking for a Windows 64-bit

Postby Silvio » Tue Aug 17, 2010 7:37 pm

Daniel,
I download all test sample
that of 32 bit run ok on xp
the second i cannot run it ( because now I use xpprofessional)
and it is ok
but if I made an application witha Windows Seven 64 bit and the I must give to customer this application it can run on xp professional 32 bit or vista 32 bit ?
I'm thinking it cannot run ....
Can I create an application run on 32 and 64 bit ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: Checking for a Windows 64-bit

Postby Daniel Garcia-Gil » Tue Aug 17, 2010 7:46 pm

Silvio...

the applications built in 64bit no run in 32bits, you can build in 32bit and run in 64bit (emulation mode)
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Checking for a Windows 64-bit

Postby Davide » Tue Aug 17, 2010 10:13 pm

Daniel,
Daniel Garcia-Gil wrote:the applications built in 64bit no run in 32bits

this is the point.
If I'm using FHW64 I have no need for a IsWin64() function because my program would not run on any other platform.
If I'm using FWH32 instead (like I am), then I need IsWow64() to know whether the host OS is a 32 or 64 bit one (and in fact I use this one to decide whether I want to send the additional 4th parameter in my modified treg.prg to read the 64bit registry entries, for example).

The only need I see for IsWin64() is when the same code can be compiled either with FWH32 or with FWH64 (like rpreview.prg does to decide which DLL it has to load), but even in this case this function returns which kind of PROGRAM is mine, rather than which kind of OS I'm running.

So, the Wiki is, at least, confusing, if not wrong at all (unless it will not specify that function will detect the real OS only with FWH64, but at that point I see no utility for such a function).

Just my 2 cents.

Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 60 guests

cron