views:

54

answers:

1

Hey

i got a little problem:

im tring to get the architecture of the OS, the problem is my programming language doesnt support such functions. Therefore i need to read this information form an windows dll (like kernel32.dll)
i did try to get the infos with the functions GetNativeSystemInfo/GetVersionEx/GetSystemInfo.
Unfortunately i were not able to get the architecture :/

Are there some other Functions to read the architecture in any windows dll?
(it dosnt need to be kernel32 it can be any dll but it must exists in win xp+)

As info: im using Gupta (SQLWindows/Team devoloper)

Edit1:

typedef struct _SYSTEM_INFO {
  union {
    DWORD  dwOemId;
    struct {
      WORD wProcessorArchitecture;
      WORD wReserved;
    } ;
  } ;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

thats the info from MSDN, i tried to call this Function with with 10 and 12 Parameters (Gupta dosnt support structs).
On 32Bit i get:
alt text

on 64Bit i get:
alt text

do i get every time a 0 OemID on 32 bit? or better is the OemID everytiem filled on 64bit version of windows?

Thx for help!!

Greets
Auro

+3  A: 

GetNativeSystemInfo is definitely the function to use. If your app is a native 64-bit app, GetNativeSystemInfo is the same as GetSystemInfo; otherwise, if it runs under WOW64, it will return the true system properties, even if it is run in an emulated 32-bit environment.

GetNativeSystemInfo fills a SYSTEM_INFO structure, the wProcessorArchitecture member of which tells you whether the system is 32-bit (probably PROCESSOR_ARCHITECTURE_INTEL) or 64-bit (probably PROCESSOR_ARCHITECTURE_AMD64).

If your language does not have a wrapper for this Win API function, to use it, you can employ LoadLibrary and GetProcAddress as usual, and you need to define the SYSTEM_INFO structure, of course.

Update

I would define

typedef struct _SYSTEM_INFO {
  WORD      wProcessorArchitecture;
  WORD      wReserved;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

Then wProcessorArchitecture = 0 on a (common) 32-bit system, and wProcessorArchitecture = 9 on a (common) 64-bit system. These are just the constants PROCESSOR_ARCHITECTURE_INTEL and PROCESSOR_ARCHITECTURE_AMD64, respectively. These are the common 32-bit and 64-bit architectures. PROCESSOR_ARCHITECTURE_IA64 = 6 is slightly more uncommon, as is surely PROCESSOR_ARCHITECTURE_UNKNOWN = 65535.

Update

Yes, I see your problem. In C, union means that you choose one of the options at a time. That is, the structure is either

DWORD     dwOemId;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

or

WORD      wProcessorArchitecture;
WORD      wReserved;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

Because one DWORD consists of as many bytes (4) as two words (2×2), the alternatives are just two ways of adressing (and naming) the data of the entire structure. In our case, we are more interested in the wProcessorArchitecture word rather then the augment dwOemId of wProcessorArchitecture and the utterly uninteresting wReserved words.

Andreas Rejbrand
see my Edit1...
Auro
looks like i cant use GetNativeSystemInfo coze its not clearly readable. Is there a way to read it out of Registry?im not sure if HKLM\Sorftware\Microsoft\Windows NT\currentVersion\BuildLabEx is save...
Auro
It is perfectly readable; see my update.
Andreas Rejbrand
Ahhh now it works perfect :Dyeah the problem were i did call the Function in Kernel32 the false way ...thx for your help!
Auro