00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <windows.h>
00016 #include <olectl.h>
00017 #include <string.h>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020
00021
00022 HANDLE g_module = NULL;
00023
00024
00025
00026
00027
00028
00029 char event_source[256] = "PostgreSQL";
00030
00031
00032 HRESULT DllInstall(BOOL bInstall, LPCWSTR pszCmdLine);
00033 STDAPI DllRegisterServer(void);
00034 STDAPI DllUnregisterServer(void);
00035 BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
00036
00037
00038
00039
00040
00041 HRESULT
00042 DllInstall(BOOL bInstall,
00043 LPCWSTR pszCmdLine)
00044 {
00045
00046 if (pszCmdLine && *pszCmdLine != '\0')
00047 wcstombs(event_source, pszCmdLine, sizeof(event_source));
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 if (bInstall)
00061 DllRegisterServer();
00062 return S_OK;
00063 }
00064
00065
00066
00067
00068
00069 STDAPI
00070 DllRegisterServer(void)
00071 {
00072 HKEY key;
00073 DWORD data;
00074 char buffer[_MAX_PATH];
00075 char key_name[400];
00076
00077
00078 if (!GetModuleFileName((HMODULE) g_module, buffer, sizeof(buffer)))
00079 {
00080 MessageBox(NULL, "Could not retrieve DLL filename", "PostgreSQL error", MB_OK | MB_ICONSTOP);
00081 return SELFREG_E_TYPELIB;
00082 }
00083
00084
00085
00086
00087
00088 _snprintf(key_name, sizeof(key_name),
00089 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
00090 event_source);
00091 if (RegCreateKey(HKEY_LOCAL_MACHINE, key_name, &key))
00092 {
00093 MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
00094 return SELFREG_E_TYPELIB;
00095 }
00096
00097
00098 if (RegSetValueEx(key,
00099 "EventMessageFile",
00100 0,
00101 REG_EXPAND_SZ,
00102 (LPBYTE) buffer,
00103 strlen(buffer) + 1))
00104 {
00105 MessageBox(NULL, "Could not set the event message file.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
00106 return SELFREG_E_TYPELIB;
00107 }
00108
00109
00110 data = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
00111
00112 if (RegSetValueEx(key,
00113 "TypesSupported",
00114 0,
00115 REG_DWORD,
00116 (LPBYTE) &data,
00117 sizeof(DWORD)))
00118 {
00119 MessageBox(NULL, "Could not set the supported types.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
00120 return SELFREG_E_TYPELIB;
00121 }
00122
00123 RegCloseKey(key);
00124 return S_OK;
00125 }
00126
00127
00128
00129
00130
00131 STDAPI
00132 DllUnregisterServer(void)
00133 {
00134 char key_name[400];
00135
00136
00137
00138
00139
00140
00141 _snprintf(key_name, sizeof(key_name),
00142 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
00143 event_source);
00144 if (RegDeleteKey(HKEY_LOCAL_MACHINE, key_name))
00145 {
00146 MessageBox(NULL, "Could not delete the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
00147 return SELFREG_E_TYPELIB;
00148 }
00149 return S_OK;
00150 }
00151
00152
00153
00154
00155
00156 BOOL WINAPI
00157 DllMain(HANDLE hModule,
00158 DWORD ul_reason_for_call,
00159 LPVOID lpReserved
00160 )
00161 {
00162 if (ul_reason_for_call == DLL_PROCESS_ATTACH)
00163 g_module = hModule;
00164 return TRUE;
00165 }