OLD | NEW |
| (Empty) |
1 // Copyright 2004-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // dynamic loading of Windows kernel32.dll API dll functions | |
17 // wrappers for win32 functions not supported on windows 95/98/ME | |
18 | |
19 #include "omaha/base/debug.h" | |
20 #include "omaha/base/dynamic_link_kernel32.h" | |
21 | |
22 namespace omaha { | |
23 | |
24 typedef BOOL (WINAPI * Module32FirstFunc)(HANDLE, LPMODULEENTRY32); | |
25 typedef BOOL (WINAPI * Module32NextFunc)(HANDLE, LPMODULEENTRY32); | |
26 typedef BOOL (WINAPI * Process32FirstFunc)(HANDLE, LPPROCESSENTRY32); | |
27 typedef BOOL (WINAPI * Process32NextFunc)(HANDLE, LPPROCESSENTRY32); | |
28 typedef BOOL (WINAPI * IsWow64ProcessFunc)(HANDLE, PBOOL); | |
29 | |
30 #define kKernel32Module L"kernel32" | |
31 | |
32 BOOL WINAPI Kernel32::Module32First(HANDLE hSnapshot, LPMODULEENTRY32 lpme) { | |
33 static Module32FirstFunc f = NULL; | |
34 | |
35 if (f == NULL) { | |
36 HMODULE handle = GetModuleHandle(kKernel32Module); | |
37 ASSERT(handle, (L"")); | |
38 f = (Module32FirstFunc) GetProcAddress(handle, "Module32FirstW"); | |
39 } | |
40 | |
41 if (f == NULL) | |
42 return FALSE; | |
43 | |
44 return f(hSnapshot, lpme); | |
45 } | |
46 | |
47 BOOL WINAPI Kernel32::Module32Next(HANDLE hSnapshot, LPMODULEENTRY32 lpme) { | |
48 static Module32NextFunc f = NULL; | |
49 | |
50 if (f == NULL) { | |
51 HMODULE handle = GetModuleHandle(kKernel32Module); | |
52 ASSERT(handle, (L"")); | |
53 f = (Module32NextFunc) GetProcAddress(handle, "Module32NextW"); | |
54 } | |
55 | |
56 if (f == NULL) | |
57 return FALSE; | |
58 | |
59 return f(hSnapshot, lpme); | |
60 } | |
61 | |
62 BOOL WINAPI Kernel32::Process32First(HANDLE hSnapshot, LPPROCESSENTRY32 lppe) { | |
63 static Process32FirstFunc f = NULL; | |
64 | |
65 if (f == NULL) { | |
66 HMODULE handle = GetModuleHandle(kKernel32Module); | |
67 ASSERT(handle, (L"")); | |
68 f = (Process32FirstFunc) GetProcAddress(handle, "Process32FirstW"); | |
69 } | |
70 | |
71 if (f == NULL) | |
72 return FALSE; | |
73 | |
74 return f(hSnapshot, lppe); | |
75 } | |
76 | |
77 BOOL WINAPI Kernel32::Process32Next(HANDLE hSnapshot, LPPROCESSENTRY32 lppe) { | |
78 static Process32NextFunc f = NULL; | |
79 | |
80 if (f == NULL) { | |
81 HMODULE handle = GetModuleHandle(kKernel32Module); | |
82 ASSERT(handle, (L"")); | |
83 f = (Process32NextFunc) GetProcAddress(handle, "Process32NextW"); | |
84 } | |
85 | |
86 if (f == NULL) | |
87 return FALSE; | |
88 | |
89 return f(hSnapshot, lppe); | |
90 } | |
91 | |
92 BOOL WINAPI Kernel32::IsWow64Process(HANDLE hProcess, PBOOL Wow64Process) { | |
93 static IsWow64ProcessFunc f = NULL; | |
94 | |
95 if (f == NULL) { | |
96 HMODULE handle = GetModuleHandle(kKernel32Module); | |
97 ASSERT(handle, (L"")); | |
98 f = (IsWow64ProcessFunc) GetProcAddress(handle, "IsWow64Process"); | |
99 } | |
100 | |
101 if (f == NULL) | |
102 return FALSE; | |
103 | |
104 return f(hProcess, Wow64Process); | |
105 } | |
106 | |
107 } // namespace omaha | |
108 | |
OLD | NEW |