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
)
57 "pushfl;" // Save flags
59 "shl $2, %%eax;" // Calculate param size
60 "subl %%eax, %%esp;" // Calculate new stack pos
61 "movl %%esp, %%edi;" // Destination is stackpointer
62 "cld;" // Clear direction flag
63 "rep movsd;" // Copy params to the stack
64 "call *%%edx;" // Call function
65 "popfl;" // Restore flags
67 : "S" (pFirstParam
), "c" (cParams
), "d"(proc
)
90 Syscall(LPWSTR pszFunction
, int cParams
, void* pParams
)
92 char szFunctionName
[MAX_PATH
];
95 sprintf(szFunctionName
, "%ls", pszFunction
);
96 proc
= (FARPROC
)GetProcAddress(g_hModule
, szFunctionName
);
99 printf("Couldn't find proc: %s\n", szFunctionName
);
103 return IntSyscall(proc
, cParams
, pParams
);
107 IsFunctionPresent(LPWSTR lpszFunction
)
109 char szFunctionName
[MAX_PATH
];
110 sprintf(szFunctionName
, "%ls", lpszFunction
);
111 return (GetProcAddress(g_hModule
, szFunctionName
) != NULL
);
115 WinMain(HINSTANCE hInstance
,
116 HINSTANCE hPrevInstance
,
120 g_hInstance
= hInstance
;
122 printf("Win32k native API test\n");
124 /* Convert to gui thread */
125 // IsGUIThread(TRUE); <- does not exists on win2k
128 printf("g_OsIdx = %d\n", g_OsIdx
);
130 g_hModule
= LoadLibraryW(L
"w32kdll.dll");
133 printf("w32kdll.dll not found!\n");
137 GdiHandleTable
= MyGdiQueryTable();
140 FreeLibrary(g_hModule
);
141 printf("GdiHandleTable not found!\n");
147 return TestMain(L
"w32knapi", L
"win32k.sys Nt-Api");