OLD | NEW |
| (Empty) |
1 // Copyright 2007-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 #include <windows.h> | |
17 #include "omaha/base/logging.h" | |
18 #include "omaha/base/omaha_version.h" | |
19 #include "omaha/base/utils.h" | |
20 #include "omaha/goopdate/goopdate.h" | |
21 #include "omaha/goopdate/omaha3_idl_datax.h" | |
22 | |
23 namespace { | |
24 | |
25 HINSTANCE dll_instance = NULL; | |
26 | |
27 } // namespace | |
28 | |
29 // Captures the module instance. Never call ::DisableThreadLibraryCalls in a | |
30 // module that statically links with LIBC and it is not using | |
31 // _beginthreadex for the thread creation. This will leak the _tiddata. | |
32 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void*) { | |
33 switch (reason) { | |
34 case DLL_PROCESS_ATTACH: | |
35 dll_instance = instance; | |
36 omaha::InitializeVersionFromModule(instance); | |
37 break; | |
38 case DLL_THREAD_ATTACH: | |
39 case DLL_THREAD_DETACH: | |
40 case DLL_PROCESS_DETACH: | |
41 default: | |
42 break; | |
43 } | |
44 | |
45 return TRUE; | |
46 } | |
47 | |
48 // Since this entry point is called by a tiny shell we've built without | |
49 // CRT support, the command line parameters contain the command line that | |
50 // the OS created the process with. By convention, the first token in the | |
51 // command line string is the filename of the program executable. The CRT takes | |
52 // care of that for program that link with the standard libraries. Therefore, | |
53 // there is a difference in the command line that the OS knows and the | |
54 // command line that is passed to WinMain by the CRT. Our command line | |
55 // parsing code takes care of this difference. | |
56 extern "C" int APIENTRY DllEntry(TCHAR* cmd_line, int cmd_show) { | |
57 OPT_LOG(L1, (_T("[DllEntry][%s]"), cmd_line)); | |
58 | |
59 bool is_local_system = false; | |
60 HRESULT hr = omaha::IsSystemProcess(&is_local_system); | |
61 assert(SUCCEEDED(hr)); // Assert because we cannot display UI here. | |
62 if (SUCCEEDED(hr)) { | |
63 omaha::Goopdate goopdate(is_local_system); | |
64 hr = goopdate.Main(dll_instance, cmd_line, cmd_show); | |
65 if (FAILED(hr)) { | |
66 OPT_LOG(LEVEL_ERROR, (_T("[Main failed][%s][0x%08x]"), cmd_line, hr)); | |
67 } | |
68 } | |
69 | |
70 OPT_LOG(L1, (_T("[DllEntry exit][0x%08x]"), hr)); | |
71 return static_cast<int>(hr); | |
72 } | |
73 | |
OLD | NEW |