|
|
Liberty Forge
Where Windows programs are hammered into
shape on the Liberty BASIC anvil
Tips & Snips
Determining the
Users Operating System
There are many situations where you might need
to determine the users OS. Some of them have to do with features available
on the different versions of Windows. Some of them have to do with
differences in API calls or the structs used in API calls.
The users O.S. and more can be found using the 'GetVersionExA'
call located in the kernel32.dll. The first thing we see is
that this call requires a struct. Since this struct must be declared
before making the call we will cover the struct first.
The required struct is defined as follows:
struct OSVInfo,_
OSVInfoSize as long,_
'the size of this struct
MajorV as long,_'returns major version number
MinorV as long,_'returns minor version number
Build as long,_'returns build number
PlatformID as long,_'returns kernel specific info
CSDV as char[128]'pointer to additional version information
Our first order of business, now that we have the struct declared,
is to set the OSVInfoSize member of the struct. This is
set to the size in bytes of memory alocated by the struct declaration
OSVInfo.OSVInfoSize.struct = len(OSVInfo.struct)
This sets the member to the number of bytes in the struct. We will
deal with making the call to 'GetVersionExA' now and discuss how
to interpret the information returned in the struct last.
In Liberty BASIC the call would be made as follows;
calldll #kernel32, "GetVersionExA",_
'the dll and calls alias
OSVInfo as struct,_
'the struct we declared above
result as long 'success or fail
Since we will discuss the struct at length in a few moments, lets cover
the result value. If the call succeeds, the result value will
be non zero. If the call fails, the result value will be zero. The most
prominent reason for this call to fail, is for the OSVInfoSize
member of our struct to be set to an invalid value. So let's
take this oportunity to make sure the call succeeded.
if result = 0 then
notice "Critical ERROR!!"+chr$(13)+"Unable to Continue"
end end if
Now lets discuss the information returned, in the struct, by the call
to 'GetVersionExA'. We already know that the first member
of the struct is used to pass the size of the struct to the API call.
The rest of the members are all used to recieve information back from the
call. The second member is the MajorV member. This contains
the major version number for the OS.
to display a table of values that might be returned for this member.
The third member is the MinorV member. This contains the minor
version number.
to display a table of values that might be returned for this member.
The next member is the Build member. This will contain the build
number. This will contain different information, depending on the Platform.
In Windows NT/2000/XP it will hold the build number only.
In Windows 95/98/ME it will be similar to an lparam, the low order word contains
the build number, and the high order word contains the major and minor versions.
This brings us to the PlatformID member. This will contain a
kernel specific identifier.
to display this members possible values.
The final member of our struct is CSDV a pointer to a null
terminated string with additional information. I have never used the
information in this member or in the Build member of this struct
so if you need to know more about them you can find it in the Platform
SDK. 99% of the time the information you need will be in the
PlatformID, MajorV, and MinorV members of
the struct.
Download the source code
|
|