4 HMODULE g_hModule
= NULL
;
5 PGDI_TABLE_ENTRY GdiHandleTable
;
11 PTEB pTeb
= NtCurrentTeb();
12 PPEB pPeb
= pTeb
->ProcessEnvironmentBlock
;
13 return pPeb
->GdiSharedHandleTable
;
17 IsHandleValid(HGDIOBJ hobj
)
19 USHORT Index
= (ULONG_PTR
)hobj
;
20 PGDI_TABLE_ENTRY pentry
= &GdiHandleTable
[Index
];
22 if (pentry
->KernelData
== NULL
||
23 pentry
->KernelData
< (PVOID
)0x80000000 ||
24 (USHORT
)pentry
->FullUnique
!= (USHORT
)((ULONG_PTR
)hobj
>> 16))
33 GetHandleUserData(HGDIOBJ hobj
)
35 USHORT Index
= (ULONG_PTR
)hobj
;
36 PGDI_TABLE_ENTRY pentry
= &GdiHandleTable
[Index
];
38 if (pentry
->KernelData
== NULL
||
39 pentry
->KernelData
< (PVOID
)0x80000000 ||
40 (USHORT
)pentry
->FullUnique
!= (USHORT
)((ULONG_PTR
)hobj
>> 16))
45 return pentry
->UserData
;
50 IntSyscall(FARPROC proc
, UINT cParams
, PVOID pFirstParam
)
56 "pushfl;" // Save flags
58 "shl $2, %%eax;" // Calculate param size
59 "subl %%eax, %%esp;" // Calculate new stack pos
60 "movl %%esp, %%edi;" // Destination is stackpointer
61 "cld;" // Clear direction flag
62 "rep movsd;" // Copy params to the stack
63 "call *%%edx;" // Call function
64 "popfl;" // Restore flags
66 : "S" (pFirstParam
), "c" (cParams
), "d"(proc
)
74 Syscall(LPWSTR pszFunction
, int cParams
, void* pParams
)
76 char szFunctionName
[MAX_PATH
];
78 sprintf(szFunctionName
, "%ls", pszFunction
);
79 FARPROC proc
= (FARPROC
)GetProcAddress(g_hModule
, szFunctionName
);
82 printf("Couldn't find proc: %s\n", szFunctionName
);
86 return IntSyscall(proc
, cParams
, pParams
);
90 IsFunctionPresent(LPWSTR lpszFunction
)
92 char szFunctionName
[MAX_PATH
];
93 sprintf(szFunctionName
, "%ls", lpszFunction
);
94 return (GetProcAddress(g_hModule
, szFunctionName
) != NULL
);
98 WinMain(HINSTANCE hInstance
,
99 HINSTANCE hPrevInstance
,
103 g_hInstance
= hInstance
;
105 printf("Win32k native API test\n");
107 /* Convert to gui thread */
108 // IsGUIThread(TRUE); <- does not exists on win2k
111 printf("g_OsIdx = %d\n", g_OsIdx
);
113 g_hModule
= LoadLibraryW(L
"w32kdll.dll");
116 printf("w32kdll.dll not found!\n");
120 GdiHandleTable
= MyGdiQueryTable();
123 FreeLibrary(g_hModule
);
124 printf("GdiHandleTable not found!\n");
130 return TestMain(L
"w32knapi", L
"win32k.sys Nt-Api");