
How to tell the difference between Windows 3.1 and 95, Please help
The following recommendation will require multiple executables for each
version you wish to address, and I don't think you want to take this
approach. That is what you are trying to avoid!
Quote:
> >In Visual Basic how Can I have my program know which OS it is running
on?
> >For Instance:
> >If win3.1 then
> > Do this
> >else if win95 then
> > Do this
> >End if
> >Please help thanks..
> Hi Robert,
> look for conditional compilation in the VB manuals.
> You have to write one code for both. Only that code, that differs, you
> have to write between the "#IF - #THEN - #ELSE". You have to compile
> twice (under WIN3.1 and under WIN95).
> Example:
> #If Win16 Then
> API16...
> #Else
> API32...
> #End If
> Gerhard Amberger, Germany
Instead ...
***********************
From Win31wh.hlp:
DWORD GetVersion(void)
The GetVersion function retrieves the current version numbers of the
Windows and MS-DOS operation systems.
Returns
The return value specifies the major and minor version numbers of Windows
and of MS-DOS.
Comments
The low-order word of the return value contains the version of Windows, if
the function is successful. The high-order byte contains the minor version
(revision) number as a two-digit decimal number. For example, in Windows
3.1, the minor version number is 10. The low-order byte contains the major
version number.
The high-order word contains the version of MS-DOS, if the function is
successful. The high-order byte contains the major version; the low-order
byte contains the minor version (revision) number.
Example
The following example uses the GetVersion function to display the Windows
and MS-DOS version numbers:
int len;
char szBuf[80];
DWORD dwVersion;
dwVersion = GetVersion();
len = sprintf(szBuf, "Windows version %d.%d\n",
LOBYTE(LOWORD(dwVersion)),
HIBYTE(LOWORD(dwVersion)));
sprintf(szBuf + len, "MS-DOS version %d.%d",
HIBYTE(HIWORD(dwVersion)),
LOBYTE(HIWORD(dwVersion)));
MessageBox(NULL, szBuf, "GetVersion", MB_ICONINFORMATION);
Note that the major and minor version information is reversed between the
Windows version and MS-DOS version.
***********************
Now in VB, you would say something like:
dim lVersion as long
dim iWinVer as integer
dim iDosVer as integer
lVersion = GetVersion()
' Since there is no bit extraction in VB, you have to do
' the math to get the high-order and low-order 16-bit words.
iWinVer = lVersion Mod 65536
iDosVer = lVersion \ 65536
' Use the same approach to get the high-order and low-order bytes.
msgbox "Windows version " & iWinVer mod 256 & "." & iWinVer \ 256
msgbox "Dos version " & iDosVer \ 256 & "." & iDosVer mod 256
Lastly you have to declare the GetVersion call
Declare Function GetVersion Lib "Kernel" () As Long
Good luck!
--
Kevin Nechodom
NurseWare