0

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

Thanks, kam

3 Answers3

2

On Windows you use IsWow64Process() function.

sharptooth
  • 167,383
  • 100
  • 513
  • 979
1

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
  • 2,700
  • 1
  • 25
  • 34
0

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:

Link

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
gtikok
  • 1,119
  • 8
  • 18
  • Could you please provide header files because i am getting some error – user489842 Oct 28 '10 at 11:26
  • How about following code if(sizeof(int) == sizeof(size_t)){printf(X86);}else{printf(x64);} – user489842 Oct 28 '10 at 11:35
  • 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 Oct 28 '10 at 11:44
  • If you're using TRUE and FALSE why not return a BOOL? – Jookia Oct 28 '10 at 11:57
  • 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? – user489842 Oct 28 '10 at 12:12
  • 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 Oct 28 '10 at 13:08