1 /*-------------------------------------------------------------------------
3 * Defines the entry point for pgbevent dll.
4 * The DLL defines event source for pgbouncer tools
5 *-------------------------------------------------------------------------
8 #define WIN32_LEAN_AND_MEAN
14 #define APP_KEY "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\pgbouncer"
16 /* Global variables */
17 static HANDLE g_module
= NULL
; /* hModule of DLL */
20 STDAPI
DllRegisterServer(void);
21 STDAPI
DllUnregisterServer(void);
22 BOOL WINAPI
DllMain(HANDLE hModule
, DWORD ul_reason_for_call
, LPVOID lpReserved
);
25 * DllRegisterServer --- Instructs DLL to create its registry entries
27 STDAPI
DllRegisterServer(void)
31 char buffer
[_MAX_PATH
];
33 /* Set the name of DLL full path name. */
34 if (!GetModuleFileName((HMODULE
)g_module
, buffer
, sizeof(buffer
))) {
35 MessageBox(NULL
, "Could not retrieve DLL filename", "pgbouncer error", MB_OK
| MB_ICONSTOP
);
36 return SELFREG_E_TYPELIB
;
40 * Add our source name as a subkey under the Application key in
41 * the EventLog registry key.
43 if (RegCreateKey(HKEY_LOCAL_MACHINE
, APP_KEY
, &key
)) {
44 MessageBox(NULL
, "Could not create the registry key.", "pgbouncer error", MB_OK
| MB_ICONSTOP
);
45 return SELFREG_E_TYPELIB
;
48 /* Add the name to the EventMessageFile subkey. */
49 if (RegSetValueEx(key
, "EventMessageFile", 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, strlen(buffer
) + 1)) {
50 MessageBox(NULL
, "Could not set the event message file.", "pgbouncer error", MB_OK
| MB_ICONSTOP
);
51 return SELFREG_E_TYPELIB
;
54 /* Set the supported event types in the TypesSupported subkey. */
55 data
= EVENTLOG_ERROR_TYPE
| EVENTLOG_WARNING_TYPE
| EVENTLOG_INFORMATION_TYPE
;
57 if (RegSetValueEx(key
, "TypesSupported", 0, REG_DWORD
, (LPBYTE
)&data
, sizeof(DWORD
))) {
58 MessageBox(NULL
, "Could not set the supported types.", "pgbouncer error", MB_OK
| MB_ICONSTOP
);
59 return SELFREG_E_TYPELIB
;
67 * DllUnregisterServer --- Instructs DLL to remove only those entries created through DllRegisterServer
69 STDAPI
DllUnregisterServer(void)
71 if (RegDeleteKey(HKEY_LOCAL_MACHINE
, APP_KEY
)) {
72 MessageBox(NULL
, "Could not delete the registry key.", "pgbouncer error", MB_OK
| MB_ICONSTOP
);
73 return SELFREG_E_TYPELIB
;
79 * DllMain --- is an optional entry point into a DLL.
81 BOOL WINAPI
DllMain(HANDLE hModule
, DWORD ul_reason_for_call
, LPVOID lpReserved
)
83 if (ul_reason_for_call
== DLL_PROCESS_ATTACH
)