tags:

views:

75

answers:

3

Hi,

I need to load dlls at runtime for 32 bit and 64 bit. how do i determine 32bit and 64bit.

Thanks, kam

+1  A: 

On Windows you use IsWow64Process() function.

sharptooth
+1. The only disadvantage of this function is that it is supported starting from Windows XP SP2. You can't use it for SP1 or clean XP.
gtikok
@gtikok: Nobody supports pre-SP2 XP.
DeadMG
You never know what platform is installed on customer PC :)
gtikok
A: 

For Windows you can use following function.

#include<Windows.h>
BOOL IsX86()
{
    char proc[9];

    GetEnvironmentVariable("PROCESSOR_ARCHITEW6432", proc, 9);

    if (lstrcmpi(proc, "AMD64") == 0)
    {
        return FALSE;
    }

    return TRUE;
}

At least it works for me.

For details please see the link:

http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx

gtikok
Could you please provide header files because i am getting some error
The header is added above.
gtikok
How about following code if(sizeof(int) == sizeof(size_t)){printf(X86);}else{printf(x64);}
I am not sure that this will work. Please see the link below. May be it will helpful. http://stackoverflow.com/questions/918787/whats-sizeofsize-t-on-32-bit-vs-the-various-64-bit-data-models
gtikok
If you're using TRUE and FALSE why not return a BOOL?
Jookia
@Jookia: You are right. BOOL should be used. Corrected.
gtikok
i set ENV32 variable in preprocess for 32bit and ENV64 for 64bit. i check the following condition #if ENV32 pritf("32bit") #elif ENV64 printf("64Bit"). Could you please which is good?
Using #if/#endif preprocessors will decrease the size of your code. Also you have to use them if you use x64 specific code which is not compiled for x86. But you still need to take into account the case when 32-bit application is executed on x64 platform. In any case it would be better if you will provide details about what you want to do exactly.
gtikok
+1  A: 

Typically this is done at build time. You produce 32-bit binaries which load 32-bit DLLs and 64-bit binaries which load 64-bit DLLs.

The user then uses the setup for her platform (32-bit installer or 64-bit installer).

So there is no need to find out at runtime on which platform you are for this.

It is not possible to load 32-bit DLLs in an 64-bit Application or the other way around.

frast