Microsoft KB Archive/75682

From BetaArchive Wiki

SAMPLE: WextMem.exe Finds Extended Memory in a Windows DLL

Q75682



The information in this article applies to:


  • Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1





SUMMARY

WextMem.exe is a file that contains source code for a Windows-based application that reports the amount of extended memory installed in the machine on which the program is run.

For a Windows-based application to determine the amount of extended memory installed in the machine on which it is running, the extended memory word can be retrieved from the machine's AT Real Time Clock/CMOS RAM. Typically, 80286, 80386 SX, 80386 DX, and i486 based computers store setup information in CMOS. This article details how to access this data.



MORE INFORMATION

The following file is available for download from the Microsoft Download Center:


WextMem.exe

For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

Q119591 How to Obtain Microsoft Support Files from Online Services

Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.



The AT Real Time Clock/CMOS RAM is accessed via port 70h, and read from and written to via port 71h. The extended memory word is stored low-order byte first in the CMOS. The first (low order) byte is stored at address 17h, and the second (high order) byte is stored at address 18h.

To read a particular address in the CMOS, write the address to read to port 70h, then retrieve the information from port 71h. Figure 1 contains a code fragment, written in Microsoft C version 6.0 with inline assembly, which shows how to check the CMOS for extended memory size. For compatibility with future versions of Windows, the following code should NOT be placed directly into a Windows-based application. Instead, this code should be placed in a dynamic-link library (DLL), which can be called by applications.

Figure 1. Sample Extended Memory Size Check

   int MemorySize = 0;

    _asm
        {
        xor   ax, ax
        mov   al, 17h
        out   70h, al
        ; jmp   $+3               ; delay not needed in most cases
        in    al, 71h
        mov   MemorySize, ax
        mov   al, 18h
        out   70h, al
        ; jmp   $+3               ; delay not needed in most cases
        in    al, 71h
        xchg  al, ah
        or    MemorySize, ax
        }

     printf("\nExtended Memory size = %u KB\n", MemorySize); 

The AT Real Time Clock/CMOS RAM configuration is documented in its entirety in the IBM PC technical reference, on pages 1-56 to 1-68. The information contained in the article was obtained from "The Programmer's PC Source Book," by Thom Hogan, published by Microsoft Press (1988).

Please note that although the BIOS on most machines automatically configures the CMOS entry for extended memory size with the amount of memory the BIOS power-on self-test (POST) routines find in the machine, some BIOS setup programs allow the user to configure the extended memory setting themselves. If the user has not filled in the correct number for the amount of extended memory installed in the machine, the check described in this article will be useless.

Additional query words:

Keywords : kbfile kbsample kb16bitonly kbKernBase kbMemory
Issue type :
Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310


Last Reviewed: December 4, 1999
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.