Use One-Time Initialization for glyph run caching to avoid duplicate glyph run genera...
[gdipp.git] / gdipp_hook / gdipp_hook.cpp
blob52d18b1b6d35b78cb4f47e92e9d73986f581d817
1 #include "stdafx.h"
2 #include "gdipp_config/constant_hook.h"
4 __declspec(dllimport) LRESULT CALLBACK gdipp_client_hook_proc(int nCode, WPARAM wParam, LPARAM lParam);
6 int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
8 const wchar_t *env_var_name = L"gdipp_svc_proc_id";
9 DWORD env_var_len = GetEnvironmentVariableW(env_var_name, NULL, 0);
10 if (env_var_len == 0)
11 return EXIT_FAILURE;
13 wchar_t *hook_env_str = new wchar_t[env_var_len];
14 env_var_len = GetEnvironmentVariableW(env_var_name, hook_env_str, env_var_len);
15 assert(env_var_len > 0);
17 DWORD gdipp_svc_proc_id;
18 std::wistringstream(hook_env_str) >> gdipp_svc_proc_id;
20 HANDLE h_gdipp_svc = OpenProcess(SYNCHRONIZE, FALSE, gdipp_svc_proc_id);
21 if (h_gdipp_svc == NULL)
22 return EXIT_FAILURE;
24 #ifdef _M_X64
25 const wchar_t *client_name = L"gdipp_client_64.dll";
26 #else
27 const wchar_t *client_name = L"gdipp_client_32.dll";
28 #endif
30 const HMODULE h_client = GetModuleHandleW(client_name);
31 assert(h_client != NULL);
33 const HHOOK h_hook = SetWindowsHookExW(WH_CBT, gdipp_client_hook_proc, h_client, 0);
34 if (h_hook == NULL)
35 return EXIT_FAILURE;
37 WaitForSingleObject(h_gdipp_svc, INFINITE);
38 UnhookWindowsHookEx(h_hook);
40 return EXIT_SUCCESS;