Delete all Trailing spaces in code.
[reactos.git] / rostests / apitests / w32knapi / w32knapi.c
1 #include "w32knapi.h"
2
3 HINSTANCE g_hInstance;
4 HMODULE g_hModule = NULL;
5 PGDI_TABLE_ENTRY GdiHandleTable;
6
7 static DWORD STDCALL
8 IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
9 {
10 DWORD ret;
11
12 asm volatile
13 (
14 "pushfl;" // Save flags
15 "movl %%ecx, %%eax;"
16 "shl $2, %%eax;" // Calculate param size
17 "subl %%eax, %%esp;" // Calculate new stack pos
18 "movl %%esp, %%edi;" // Destination is stackpointer
19 "cld;" // Clear direction flag
20 "rep movsd;" // Copy params to the stack
21 "call *%%edx;" // Call function
22 "popfl;" // Restore flags
23 : "=a" (ret)
24 : "S" (pFirstParam), "c" (cParams), "d"(proc)
25 : "%edi"
26 );
27
28 return ret;
29 }
30
31 DWORD
32 Syscall(LPWSTR pszFunction, int cParams, void* pParams)
33 {
34 char szFunctionName[MAX_PATH];
35
36 sprintf(szFunctionName, "%ls", pszFunction);
37 FARPROC proc = (FARPROC)GetProcAddress(g_hModule, szFunctionName);
38 if (!proc)
39 {
40 printf("Couldn't find proc: %s\n", szFunctionName);
41 return FALSE;
42 }
43
44 return IntSyscall(proc, cParams, pParams);
45 }
46
47 BOOL
48 IsFunctionPresent(LPWSTR lpszFunction)
49 {
50 char szFunctionName[MAX_PATH];
51 sprintf(szFunctionName, "%ls", lpszFunction);
52 return (GetProcAddress(g_hModule, szFunctionName) != NULL);
53 }
54
55 int APIENTRY
56 WinMain(HINSTANCE hInstance,
57 HINSTANCE hPrevInstance,
58 LPSTR lpCmdLine,
59 int nCmdShow)
60 {
61 g_hInstance = hInstance;
62 GDIQUERYPROC GdiQueryHandleTable;
63
64 printf("Win32k native API test\n");
65
66 /* Convert to gui thread */
67 // IsGUIThread(TRUE); <- does not exists on win2k
68
69 g_hModule = LoadLibraryW(L"w32kdll.dll");
70 if (!g_hModule)
71 {
72 printf("w32kdll.dll not found!\n");
73 return -1;
74 }
75
76 GdiQueryHandleTable = (GDIQUERYPROC)GetProcAddress(GetModuleHandleW(L"GDI32.DLL"), "GdiQueryTable");
77 if(!GdiQueryHandleTable)
78 {
79 return -1;
80 }
81 GdiHandleTable = GdiQueryHandleTable();
82 if(!GdiHandleTable)
83 {
84 return -1;
85 }
86
87 printf("\n");
88
89 return TestMain(L"w32knapi", L"win32k.sys Nt-Api");
90 }