Page 1 of 2

Checking for a Windows 64-bit

PostPosted: Tue Jun 29, 2010 9:09 am
by driessen
Hello,

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

Thanks you very much in advance.

Re: Checking for a Windows 64-bit

PostPosted: Tue Jun 29, 2010 9:32 am
by Antonio Linares

Re: Checking for a Windows 64-bit

PostPosted: Fri Aug 13, 2010 1:29 am
by Davide
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

Re: Checking for a Windows 64-bit

PostPosted: Fri Aug 13, 2010 11:08 pm
by Davide
Simple test:

Image

Nobody's using IsWin64() here ?

Hi,
Davide

Re: Checking for a Windows 64-bit

PostPosted: Sat Aug 14, 2010 1:09 am
by Davide
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

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

Re: Checking for a Windows 64-bit

PostPosted: Sun Aug 15, 2010 6:27 pm
by Daniel Garcia-Gil
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*/
 

Re: Checking for a Windows 64-bit

PostPosted: Mon Aug 16, 2010 9:07 am
by Davide
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

Re: Checking for a Windows 64-bit

PostPosted: Mon Aug 16, 2010 10:52 am
by Daniel Garcia-Gil
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 );
}
 

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 1:05 am
by Davide
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

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 1:50 am
by Daniel Garcia-Gil
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

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 7:54 am
by StefanHaupt
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...

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 10:51 am
by Daniel Garcia-Gil
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

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 7:37 pm
by Silvio
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 ?

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 7:46 pm
by Daniel Garcia-Gil
Silvio...

the applications built in 64bit no run in 32bits, you can build in 32bit and run in 64bit (emulation mode)

Re: Checking for a Windows 64-bit

PostPosted: Tue Aug 17, 2010 10:13 pm
by Davide
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