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