📄 dtwinver.cpp
字号:
//must be running on a real version of 16 bit Windows whose underlying OS is DOS
lpVersionInformation->dwUnderlyingMajorVersion = HIBYTE(HIWORD(dwVersion));
lpVersionInformation->dwUnderlyingMinorVersion = LOBYTE(HIWORD(dwVersion));
lpVersionInformation->dwUnderlyingBuildNumber = 0;
lpVersionInformation->dwUnderlyingPlatformId = PLATFORM_DOS;
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "MS-DOS");
}
#else //Must be some version of real or emulated Dos
//Retreive the current version of emulated dos
BYTE DosMinor;
BYTE DosMajor;
_asm
{
mov ax, 3306h
int 21h
mov byte ptr [DosMajor], bl
mov byte ptr [DosMinor], bh
}
lpVersionInformation->dwEmulatedPlatformId = PLATFORM_DOS;
lpVersionInformation->dwEmulatedMajorVersion = (DWORD) DosMajor;
lpVersionInformation->dwEmulatedMinorVersion = (DWORD) DosMinor;
lpVersionInformation->dwEmulatedBuildNumber = 0; //no build number with Dos
//We can detect if NT is running as it reports Dos v5.5
if ((lpVersionInformation->dwEmulatedMajorVersion == 5) &&
(lpVersionInformation->dwEmulatedMinorVersion == 50)) //NT reports Dos v5.5
{
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "Microsoft Windows NT");
//could not find method of determing version of NT from Dos,
//so assume 3.50
lpVersionInformation->dwUnderlyingMajorVersion = 3;
lpVersionInformation->dwUnderlyingMinorVersion = 50;
lpVersionInformation->dwUnderlyingBuildNumber = 0; //cannot get access to build number from Dos
lpVersionInformation->dwUnderlyingPlatformId = PLATFORM_NT_WORKSTATION;
}
else
{
//Get the underlying OS here via the int 2FH interface of Windows
GetWinInfo();
if (bRunningWindows)
{
if (lpVersionInformation->dwEmulatedMajorVersion >= 7) //Windows 95 marks itself as Dos 7
lpVersionInformation->dwUnderlyingPlatformId = PLATFORM_WINDOWS;
else
{
//Could not find method of differentiating between WFW & Win3.1 under Dos,
//so assume Win3.1
lpVersionInformation->dwUnderlyingPlatformId = PLATFORM_WINDOWS31;
}
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "Microsoft Windows");
lpVersionInformation->dwUnderlyingMajorVersion = (WinVer & 0xFF00) >> 8;
lpVersionInformation->dwUnderlyingMinorVersion = WinVer & 0x00FF;
lpVersionInformation->dwUnderlyingBuildNumber = 0; //cannot get access to build number from Dos
}
else //must be on a real version of Dos
{
lpVersionInformation->dwUnderlyingMajorVersion = (DWORD) DosMajor;
lpVersionInformation->dwUnderlyingMinorVersion = (DWORD) DosMinor;
lpVersionInformation->dwUnderlyingBuildNumber = 0; //no build number with Dos
lpVersionInformation->dwUnderlyingPlatformId = PLATFORM_DOS;
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "MS-DOS");
}
}
#endif
#endif
return TRUE;
}
#ifdef _WIN32
BOOL WhichNTProduct(DWORD& dwVersion)
{
const int MY_BUFSIZE = 100;
TCHAR szProductType[MY_BUFSIZE];
DWORD dwBufLen = MY_BUFSIZE * sizeof(TCHAR);
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
0,
KEY_EXECUTE,
&hKey) != ERROR_SUCCESS)
return FALSE;
if (RegQueryValueEx(hKey,
_T("ProductType"),
NULL,
NULL,
(LPBYTE) szProductType,
&dwBufLen) != ERROR_SUCCESS)
return FALSE;
RegCloseKey(hKey);
BOOL bSuccess = FALSE;
// check product options, in order of likelihood
if (_tcsicmp(_T("WINNT"), szProductType) == 0)
{
dwVersion = PLATFORM_NT_WORKSTATION;
bSuccess = TRUE;
}
else if ((_tcsicmp(_T("SERVERNT"), szProductType) == 0) || (_tcsicmp(_T("LANMANNT"), szProductType) == 0))
{
dwVersion = PLATFORM_NT_SERVER;
bSuccess = TRUE;
}
return bSuccess;
}
#endif
#if defined(_WINDOWS) && !defined(_WIN32)
UINT WINAPI WOWCreateVDMPointer16(DWORD dwLinBase, DWORD dwLimit)
{
UINT uSelector, uDSSel;
if (!(dwCapBits & WOW_VDMPTR16))
return NULL;
// Grab our DS (for access rights)
__asm mov uDSSel, ds
// Allocate a new selector
uSelector = AllocSelector(uDSSel);
if (uSelector)
{
// Assign its linear base address and limit
SetSelectorBase(uSelector, dwLinBase);
SetSelectorLimit(uSelector, dwLimit);
}
return uSelector;
}
UINT WINAPI WOWDeleteVDMPointer16(UINT uSelector)
{
if (!(dwCapBits & WOW_VDMPTR16))
return NULL;
return FreeSelector(uSelector);
}
HWND32 WINAPI WOWHwndToHwnd32(HWND hWnd)
{
if (!(dwCapBits & WOW_HWND32))
return NULL;
// OR mask the upper 16 bits
HWND32 hWnd32 = (HWND32) (WORD) (hWnd);
return (hWnd32 | 0xffff0000);
}
HINSTANCE32 WINAPI WOWLoadLibraryEx32(LPSTR lpszFile, HFILE32 hFile,
DWORD dwFlags)
{
if (!(dwCapBits & WOW_LOADLIBRARY))
return NULL;
return LoadLibraryEx32W(lpszFile, hFile, dwFlags);
}
BOOL WINAPI WOWFreeLibrary32(HINSTANCE32 hInst32)
{
if (!(dwCapBits & WOW_FREELIBRARY))
return NULL;
return FreeLibrary32W(hInst32);
}
FARPROC WINAPI WOWGetProcAddress32(HINSTANCE32 hInst32,
LPCSTR lpszProc)
{
if (!(dwCapBits & WOW_GETPROCADDRESS))
return NULL;
return GetProcAddress32W(hInst32, lpszProc);
}
DWORD WINAPI WOWGetVDMPointer32(LPVOID lpAddress, UINT fMode)
{
if (!(dwCapBits & WOW_VDMPTR32))
return NULL;
return GetVDMPointer32W(lpAddress, fMode);
}
DWORD WOWCallProc32(FARPROC lpfnFunction, DWORD dwAddressConvert, DWORD dwParams, ...)
{
va_list vaList;
DWORD dwCount;
DWORD dwTemp;
if (!(dwCapBits & WOW_CALLPROC))
return NULL;
// Variable list start
va_start(vaList,dwParams);
for(dwCount=0; dwCount < dwParams; dwCount++)
{
// Pull each variable off of the stack
dwTemp=(DWORD)va_arg(vaList,DWORD);
// Push the DWORD
__asm push word ptr [dwTemp+2];
__asm push word ptr [dwTemp];
}
// Variable list end
va_end(vaList);
// Call Win32. The pushed variable list precedes the parameters.
// Appropriate parameters will be popped by this function (based
// on the value in dwParams)
return CallProc32W(lpfnFunction, dwAddressConvert, dwParams);
}
BOOL WFWLoaded()
{
const WORD WNNC_NET_MultiNet = 0x8000;
const WORD WNNC_SUBNET_WinWorkgroups = 0x0004;
const WORD WNNC_NET_TYPE = 0x0002;
BOOL rVal;
HINSTANCE hUserInst = LoadLibrary("USER.EXE");
lpfnWNetGetCaps lpWNetGetCaps = (lpfnWNetGetCaps) GetProcAddress(hUserInst, "WNetGetCaps");
if (lpWNetGetCaps != NULL)
{
// Get the network type
WORD wNetType = lpWNetGetCaps(WNNC_NET_TYPE);
if (wNetType & WNNC_NET_MultiNet)
{
// a multinet driver is installed
if (LOBYTE(wNetType) & WNNC_SUBNET_WinWorkgroups) // It is WFW
rVal = TRUE;
else // It is not WFW
rVal = FALSE;
}
else
rVal = FALSE;
}
else
rVal = FALSE;
// Clean up the module instance
if (hUserInst)
FreeLibrary(hUserInst);
return rVal;
}
#endif //defined(_WINDOWS) && !defined(_WIN32)
#ifdef _DOS
void GetWinInfo()
{
BYTE MajorVer;
BYTE MinorVer;
//use some inline assembly to determine if Windows if
//running and what version is active
_asm
{
; check for Windows 3.1
mov ax,160ah ; WIN31CHECK
int 2fh ; check if running under Win 3.1.
or ax,ax
jz RunningUnderWin31 ; can check if running in standard
; or enhanced mode
; check for Windows 3.0 enhanced mode
mov ax,1600h ; WIN386CHECK
int 2fh
test al,7fh
jnz RunningUnderWin30Enh ; enhanced mode
; check for 3.0 WINOLDAP
mov ax,4680h ; IS_WINOLDAP_ACTIVE
int 2fh
or ax,ax ; running under 3.0 derivative?
jnz NotRunningUnderWin
; rule out MS-DOS 5.0 task switcher
mov ax,4b02h ; detect switcher
push bx
push es
push di
xor bx,bx
mov di,bx
mov es,bx
int 2fh
pop di
pop es
pop bx
or ax,ax
jz NotRunningUnderWin ; MS-DOS 5.0 task switcher found
; check for standard mode Windows 3.0
mov ax,1605h ; PMODE_START
int 2fh
cmp cx,-1
jz RunningUnderWin30Std
; check for real mode Windows 3.0
mov ax,1606h ; PMODE_STOP
int 2fh ; in case someone is counting
; Real mode Windows 3.0 is running
mov byte ptr [bRunningWindows], 1
mov byte ptr [MajorVer], 3h
mov byte ptr [MinorVer], 0h
jmp ExitLabel
RunningUnderWin30Std:
; Standard mode Windows 3.0 is running
mov byte ptr [bRunningWindows], 1
mov byte ptr [MajorVer], 3h
mov byte ptr [MinorVer], 0h
jmp ExitLabel
RunningUnderWin31:
; At this point: CX == 3 means Windows 3.1 enhanced mode
; CX == 2 means Windows 3.1 standard mode
mov byte ptr [bRunningWindows], 1
; Get the version of Windows
mov ax, 1600h ; Get Enhanced-Mode Windows Installed State
int 2Fh
mov byte ptr [MajorVer], al
mov byte ptr [MinorVer], ah
jmp ExitLabel
RunningUnderWin30Enh:
; Enhanced mode Windows 3.0 is running
mov byte ptr [bRunningWindows], 1
mov byte ptr [MajorVer], 3h
mov byte ptr [MinorVer], 0h
jmp ExitLabel
NotRunningUnderWin:
mov byte ptr [bRunningWindows], 0
ExitLabel:
}
WinVer = (WORD) ((MajorVer << 8) + MinorVer);
}
#endif //_DOS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -