Getting free resource under Windows 95

How to call 16-bit dll API from 32-bit application.

Windows 95 secret finally revealed.

One of the most frequently asked question about Windows95 is "How does Windows Explorer get the amount of system resources available?"

The Microsoft documentation states that the GetFreeSystemResources function is discontinued for Win32. Win32 documentation also says that system resources are virtually unlimited now. However Windows Explorer Help About dialog shows that it is not correct (at least for Windows95). I haven't tested this on Windows98 as of yet and and I believe that the documentation is correct with regards to WindowsNT. However, for Windows95, they documentation is definitely in error.

The 16-bit module USER.EXE still exists in Windows95 and 16-bit applications can get retrieve the desired resource information using the 16-bit GetFreeSystemResources function. So, the question is, Why can't Explorer (or any 32-bit application) also make this call?

The code snippet below demonstrates how to invoke a function exported from a 16-bit DLL from a 32-bit application. Please note that the GetK32ProcAddress function was provided courtesy of Andrew Schulman's "Unauthorized Windows 95 Update". For the more curious among you, here are the links to the header and implentation files for that function.

http://ftp.uni-mannheim.de/info/OReilly/windows/win95.update/k32exp.c

http://ftp.uni-mannheim.de/info/OReilly/windows/win95.update/k32exp.h

(Since k32exp.c is included as a separate module, I'm guessing that it is protected by copyright.)


WORD GetFreeSystemResources(WORD type)
{
 //Decarations  "c" style
 typedef HINSTANCE (WINAPI* LOADLIB16)(char*);
 typedef LONG (WINAPI* GETPROC16)(HINSTANCE, LPCSTR);
 typedef BOOL (WINAPI* FREELIB16)(HINSTANCE);
 FARPROC QT_Thunk;
 
 LOADLIB16 pLoadLib16;
 GETPROC16 pGetProc16;
 FREELIB16 pFreeLib16;
 HINSTANCE hInst;
 DWORD pGetRes;
 WORD user_fsr;
 WORD _type;
 HMODULE hKernel;

 //Usuall Windows API calls
 hKernel = GetModuleHandle("KERNEL32");
 QT_Thunk = GetProcAddress(hKernel, "QT_Thunk");

 //Andrew Schulman's 
 pLoadLib16 = (LOADLIB16) GetK32ProcAddress(LOADLIBRARY16_ORD);
 pGetProc16 = (GETPROC16) GetK32ProcAddress(GETPROCADDRESS16_ORD);
 pFreeLib16 = (FREELIB16) GetK32ProcAddress(FREELIBRARY16_ORD);

 //Usuall for "c"-style calls - by pointer to function 
 hInst = (*pLoadLib16)("user");
 (*pFreeLib16)(hInst);
 pGetRes = (*pGetProc16)(hInst,"GetFreeSystemResources");

 //How to call 16-bit dll API from 32-bit .exe using QT_Thunk function
 _type = type;
 if (pGetRes)
 _asm
 {  	
  push    _type
  mov     edx, [pGetRes] 
  call    QT_Thunk 
  mov     [user_fsr], ax
 }
 return user_fsr;
}
The demo project included in this article is a console application that retrieves the free system resources for Windows 95. Simply build it and run it from the command line.

How do you know that the Windows95 Explorer uses the 16-bit USER.EXE to get free system resources? Just ask your buddy hacker to make GetFreeSystemResources in USER.EXE return zero and examine what Windows Explorer shows for free resources!. In my USER.EXE version 4.00.950, GetFreeSystemResources starts at the 0x444FF byte offset.

Download demo project - 5 in KB KB

Date Last Updated: February 8, 1999



Comments

  • free disk space from Windows NT machine.

    Posted by Legacy on 01/17/2001 12:00am

    Originally posted by: Arun Jose

    How t get the free available disk space in Windows NT machine???

    Reply
  • Direct thunk problems

    Posted by Legacy on 09/27/1999 12:00am

    Originally posted by: PetrP

    I had to add extern "C" to k32exp.h to link it to my 32-bit application. Finaly this code is very helpful for all thunks programmers.

    I try to call my own 16-bit dll with no problems when passing constants through direct thunk, but I have problems with pointers now. I load procedure by LoadLib16() and GetProcAdress16(), then I allocate memory by GlobalAlloc16(), move data by MoveMemory(), call QT_Thunk passing pointer, then I free memory by GlobalFree16(). All is working until this. I try to free called procedure and library by FreeLib16() and error occures.

    When using another procedure from this same library without pointers everithing goes OK.

    What I'm doing wrong... Please HELP ME !

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Corporate e-Learning technology has a long and diverse pedigree. As far back as the 1980s, companies were adopting computer-based training to supplement traditional classroom activities. More recently, rich web-based applications have added streaming audio and video, real-time collaboration and other new tools to the e-Learning mix. At the same time, the growing availability of informal learning tools--a category that includes everything from web searches to social media posts--are having a major impact on …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds