summaryrefslogtreecommitdiffstats
path: root/private/mvdm/wow16/toolhelp/usergdi1.c
blob: 05aac84cef41de3e4a1da5ff4458cdd9031192bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**************************************************************************
 *  USERGDI1.C
 *
 *      Returns information about USER.EXE and GDI.EXE
 *
 **************************************************************************/

#include "toolpriv.h"

/*  SystemHeapInfo
 *      Returns information about USER's and GDI's heaps
 */

BOOL TOOLHELPAPI SystemHeapInfo(
    SYSHEAPINFO FAR* lpSysHeap)
{
    MODULEENTRY ModuleEntry;
#ifndef WOW
    DWORD dw;
    WORD wFreeK;
    WORD wMaxHeapK;
#endif

    /* Check the structure version number and pointer */
    if (!wLibInstalled || !lpSysHeap ||
        lpSysHeap->dwSize != sizeof (SYSHEAPINFO))
        return FALSE;

    /* Find the user data segment */
    ModuleEntry.dwSize = sizeof (MODULEENTRY);
    lpSysHeap->hUserSegment =
        UserGdiDGROUP(ModuleFindName(&ModuleEntry, "USER"));
    lpSysHeap->hGDISegment =
        UserGdiDGROUP(ModuleFindName(&ModuleEntry, "GDI"));

#ifndef WOW
    /* We get the information about the heap percentages differently in
     *  3.0 and 3.1
     */
    if ((wTHFlags & TH_WIN30) || !lpfnGetFreeSystemResources)
    {
        /* Get the space information about USER's heap */
        dw = UserGdiSpace(lpSysHeap->hUserSegment);
        wFreeK = LOWORD(dw) / 1024;
        wMaxHeapK = HIWORD(dw) / 1024;
        if (wMaxHeapK)
            lpSysHeap->wUserFreePercent = wFreeK * 100 / wMaxHeapK;
        else
            lpSysHeap->wUserFreePercent = 0;

        /* Get the space information about GDI's heap */
        dw = UserGdiSpace(lpSysHeap->hGDISegment);
        wFreeK = LOWORD(dw) / 1024;
        wMaxHeapK = HIWORD(dw) / 1024;
        if (wMaxHeapK)
            lpSysHeap->wGDIFreePercent = wFreeK * 100 / wMaxHeapK;
        else
            lpSysHeap->wGDIFreePercent = 0;
    }

    /* Get the information from USER in 3.1 */
    else
    {
        lpSysHeap->wUserFreePercent =
            (*(WORD (FAR PASCAL *)(WORD))lpfnGetFreeSystemResources)(2);
        lpSysHeap->wGDIFreePercent =
            (*(WORD (FAR PASCAL *)(WORD))lpfnGetFreeSystemResources)(1);
    }
#else

    lpSysHeap->wUserFreePercent = GetFreeSystemResources(GFSR_USERRESOURCES);
    lpSysHeap->wGDIFreePercent = GetFreeSystemResources(GFSR_GDIRESOURCES);

#endif

    return TRUE;
}