|
| 1 | +/*------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * pgevent.c |
| 4 | + * Defines the entry point for pgevent dll. |
| 5 | + * The DLL defines event source for backend |
| 6 | + * |
| 7 | + * |
| 8 | + * IDENTIFICATION |
| 9 | + * $PostgreSQL: pgsql/src/bin/pgevent/pgevent.c,v 1.1 2004/06/20 01:32:49 momjian Exp $ |
| 10 | + * |
| 11 | + *------------------------------------------------------------------------- |
| 12 | + */ |
| 13 | + |
| 14 | + |
| 15 | +#include "windows.h" |
| 16 | +#include "olectl.h" |
| 17 | +#include "string.h" |
| 18 | + |
| 19 | +/* Global variables */ |
| 20 | +HANDLE g_module = NULL; /* hModule of DLL */ |
| 21 | + |
| 22 | +/* Prototypes */ |
| 23 | +STDAPI DllRegisterServer(void) ; |
| 24 | +STDAPI DllUnregisterServer(void); |
| 25 | +BOOL WINAPI DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ); |
| 26 | + |
| 27 | +/* |
| 28 | + * DllRegisterServer --- Instructs DLL to create its registry entries |
| 29 | + */ |
| 30 | + |
| 31 | +STDAPI DllRegisterServer(void) |
| 32 | +{ |
| 33 | + HKEY key; |
| 34 | + DWORD data; |
| 35 | + char buffer[_MAX_PATH]; |
| 36 | + |
| 37 | + /* Set the name of DLL full path name. */ |
| 38 | + if (!GetModuleFileName((HMODULE)g_module, buffer, sizeof(buffer))) |
| 39 | + { |
| 40 | + MessageBox(NULL, "Could not retrieve DLL filename", "PostgreSQL error", MB_OK|MB_ICONSTOP); |
| 41 | + return SELFREG_E_TYPELIB; |
| 42 | + } |
| 43 | + |
| 44 | + /* Add PostgreSQL source name as a subkey under the Application |
| 45 | + key in the EventLog registry key. */ |
| 46 | + if ( RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\PostgreSQL", &key) ) |
| 47 | + { |
| 48 | + MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK|MB_ICONSTOP); |
| 49 | + return SELFREG_E_TYPELIB; |
| 50 | + } |
| 51 | + |
| 52 | + /* Add the name to the EventMessageFile subkey. */ |
| 53 | + if (RegSetValueEx(key, |
| 54 | + "EventMessageFile", |
| 55 | + 0, |
| 56 | + REG_EXPAND_SZ, |
| 57 | + (LPBYTE) buffer, |
| 58 | + strlen(buffer) + 1)) |
| 59 | + { |
| 60 | + MessageBox(NULL, "Could not set the event message file.", "PostgreSQL error", MB_OK|MB_ICONSTOP); |
| 61 | + return SELFREG_E_TYPELIB; |
| 62 | + } |
| 63 | + |
| 64 | + /* Set the supported event types in the TypesSupported subkey. */ |
| 65 | + data = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; |
| 66 | + |
| 67 | + if (RegSetValueEx(key, |
| 68 | + "TypesSupported", |
| 69 | + 0, |
| 70 | + REG_DWORD, |
| 71 | + (LPBYTE) &data, |
| 72 | + sizeof(DWORD))) |
| 73 | + { |
| 74 | + MessageBox(NULL, "Could not set the supported types.", "PostgreSQL error", MB_OK|MB_ICONSTOP); |
| 75 | + return SELFREG_E_TYPELIB; |
| 76 | + } |
| 77 | + |
| 78 | + RegCloseKey(key); |
| 79 | + return S_OK; |
| 80 | +} |
| 81 | + |
| 82 | +/* |
| 83 | + * DllUnregisterServer --- Instructs DLL to remove only those entries created through DllRegisterServer |
| 84 | + */ |
| 85 | + |
| 86 | +STDAPI DllUnregisterServer(void) |
| 87 | +{ |
| 88 | + /* Remove PostgreSQL source name as a subkey under the Application |
| 89 | + key in the EventLog registry key. */ |
| 90 | + |
| 91 | + if ( RegDeleteKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\PostgreSQL") ) |
| 92 | + { |
| 93 | + MessageBox(NULL, "Could not delete the registry key.", "PostgreSQL error", MB_OK|MB_ICONSTOP); |
| 94 | + return SELFREG_E_TYPELIB; |
| 95 | + } |
| 96 | + return S_OK; |
| 97 | +} |
| 98 | + |
| 99 | +/* |
| 100 | + * DllMain --- is an optional entry point into a DLL. |
| 101 | + */ |
| 102 | + |
| 103 | +BOOL WINAPI DllMain( HANDLE hModule, |
| 104 | + DWORD ul_reason_for_call, |
| 105 | + LPVOID lpReserved |
| 106 | + ) |
| 107 | +{ |
| 108 | + if ( ul_reason_for_call == DLL_PROCESS_ATTACH ) |
| 109 | + { |
| 110 | + g_module = hModule; |
| 111 | + } |
| 112 | + return TRUE; |
| 113 | +} |
| 114 | + |
0 commit comments