home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n12
/
undr1295.exe
/
WIN95WND.CPP
next >
Wrap
C/C++ Source or Header
|
1995-12-01
|
3KB
|
103 lines
//==================================
// WIN95WND - Matt Pietrek 1995
// FILE: WIN95WND.CPP
//==================================
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#pragma hdrstop
//------------------------ Prototypes ---------------------------------------
// Get the 32 bit linear address of USER.EXE's DGROUP segment
DWORD GetUSER16DGroupLinearAddress( void );
// Given an HWND, return the linear address of its corresponding WND structure
PVOID HWndToLinearAddress( HWND hWnd );
// Self-explanatory
BOOL IsWindows95( void );
//-------------------------- Start of code ----------------------------------
int main( int argc, char *argv[] )
{
HWND hWndDesktop, hWndDesktop2;
PVOID pDesktopWindow; // Linear address of the WND structure
if ( !IsWindows95() )
{
printf( "%s only runs on Windows 95\n", argv[0] );
return 1;
}
hWndDesktop = GetDesktopWindow(); // Get the desktop HWND
// Get the linear address of the desktop HWND
pDesktopWindow = HWndToLinearAddress( hWndDesktop );
// Reach 0x46 bytes into the WND structure and grab out the 16 bit HWND
hWndDesktop2 = (HWND) *(PWORD)((DWORD)pDesktopWindow + 0x46);
printf("Desktop HWND:%04X Address:%08X HWND from WND struct:%04X",
hWndDesktop, pDesktopWindow, hWndDesktop2 );
return 0;
}
// Given an HWND, return the linear address of its corresponding WND structure
PVOID HWndToLinearAddress( HWND hWnd )
{
if ( !IsWindow(hWnd) )
return 0;
DWORD user16DgroupBase = GetUSER16DGroupLinearAddress();
if ( !user16DgroupBase )
return 0;
// Add USER.EXE's DGROUP address, the handle conversion table
// offset (0x10000), and the hWnd value to get a pointer to the
// WND pointer. This WND ptr is relative to USER.EXE's DGROUP.
DWORD WND_offset = *(PDWORD)(user16DgroupBase + 0x10000 + (DWORD)hWnd);
// Take the USER.EXE DGROUP relative pointer, add the USER.EXE DGROUP
// base to it, and return the result.
return (PVOID)(user16DgroupBase + WND_offset);
}
// Get the 32 bit linear address of USER.EXE's DGROUP segment
DWORD GetUSER16DGroupLinearAddress( void )
{
// The desktop window is created by USER.EXE, so it will have USER.EXE's
// HINSTANCE
DWORD USER16_hInstance = GetWindowLong(GetDesktopWindow(), GWL_HINSTANCE);
if ( !USER16_hInstance )
return 0;
LDT_ENTRY descriptor;
// Use GetThreadSelectorEntry to copy the descriptor associated with
// USER.EXE's DGROUP selector
if ( FALSE == GetThreadSelectorEntry( GetCurrentThread(),
USER16_hInstance,
&descriptor) )
return 0;
// Assemble the components of the descriptor into a usable linear address
return (descriptor.HighWord.Bytes.BaseHi << 24 )
+ (descriptor.HighWord.Bytes.BaseMid << 16 )
+ descriptor.BaseLow;
}
// Self-explanatory
BOOL IsWindows95( void )
{
if ( 0 == (GetVersion() & 0x80000000) ) // High bit not set for NT
return FALSE;
if ( LOBYTE(GetVersion()) != 4 ) // Win95 is version 4. Win32s
return FALSE; // shows up as version 3.
// Disallow all other versions.
return TRUE;
}