Use Slim Reader/Writer lock to replace CRITICAL_SECTION (better performance).
[gdipp.git] / gdipp_client / gdipp_client.cpp
blob72961c1660614aa5ae6fddeab9ab68b15dfc279e
1 #include "stdafx.h"
2 #include "gdipp_client/gamma.h"
3 #include "gdipp_client/global.h"
4 #include "gdipp_config/constant_client.h"
5 #include "gdipp_config/exclude_config.h"
6 #include "gdipp_lib/helper.h"
7 #include "gdipp_lib/scoped_rw_lock.h"
9 namespace gdipp
12 HANDLE process_heap = GetProcessHeap();
14 bool init_rpc_client()
16 if (process_heap == NULL)
17 return false;
19 RPC_WSTR binding_str;
20 RPC_STATUS rpc_status;
22 rpc_status = RpcStringBindingCompose(NULL, reinterpret_cast<RPC_WSTR>(L"ncalrpc"), NULL, reinterpret_cast<RPC_WSTR>(L"gdipp"), NULL, &binding_str);
23 if (rpc_status != RPC_S_OK)
24 return false;
26 rpc_status = RpcBindingFromStringBinding(binding_str, &h_gdipp_rpc);
27 if (rpc_status != RPC_S_OK)
28 return false;
30 rpc_status = RpcStringFree(&binding_str);
31 if (rpc_status != RPC_S_OK)
32 return false;
34 return true;
39 void __RPC_FAR *__RPC_USER MIDL_user_allocate(size_t size)
41 return HeapAlloc(gdipp::process_heap, HEAP_GENERATE_EXCEPTIONS, size);
44 void __RPC_USER MIDL_user_free(void __RPC_FAR *ptr)
46 HeapFree(gdipp::process_heap, 0, ptr);
49 BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
51 BOOL b_ret;
53 switch (ul_reason_for_call)
55 case DLL_PROCESS_ATTACH:
57 gdipp::h_self = hModule;
59 wchar_t this_proc_name[MAX_PATH];
60 DWORD dw_ret = GetModuleBaseNameW(GetCurrentProcess(), NULL, this_proc_name, MAX_PATH);
61 assert(dw_ret != 0);
63 if (gdipp::exclude_config::is_process_excluded(gdipp::config_instance, this_proc_name))
64 return FALSE;
66 OSVERSIONINFO ver_info = {sizeof(OSVERSIONINFO)};
67 b_ret = GetVersionEx(&ver_info);
68 if (!b_ret)
69 return FALSE;
70 gdipp::os_support_directwrite = (ver_info.dwMajorVersion >= 6);
72 gdipp::scoped_rw_lock::initialize();
74 if (!gdipp::init_rpc_client())
75 return FALSE;
77 gdipp::client_config_instance.parse(gdipp::config_instance);
79 if (!gdipp::hook_instance.start())
80 return FALSE;
82 break;
84 case DLL_PROCESS_DETACH:
85 gdipp::hook_instance.stop();
86 break;
89 return TRUE;