PostgreSQL Source Code git master
pgevent.c File Reference
#include "postgres_fe.h"
#include <olectl.h>
Include dependency graph for pgevent.c:

Go to the source code of this file.

Functions

HRESULT DllInstall (BOOL bInstall, LPCWSTR pszCmdLine)
 
STDAPI DllRegisterServer (void)
 
STDAPI DllUnregisterServer (void)
 
BOOL WINAPI DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
 

Variables

static HANDLE g_module = NULL
 
static char event_source [256] = DEFAULT_EVENT_SOURCE
 

Function Documentation

◆ DllInstall()

HRESULT DllInstall ( BOOL  bInstall,
LPCWSTR  pszCmdLine 
)

Definition at line 38 of file pgevent.c.

40{
41 if (pszCmdLine && *pszCmdLine != '\0')
42 wcstombs(event_source, pszCmdLine, sizeof(event_source));
43
44 /*
45 * This is an ugly hack due to the strange behavior of "regsvr32 /i".
46 *
47 * When installing, regsvr32 calls DllRegisterServer before DllInstall.
48 * When uninstalling (i.e. "regsvr32 /u /i"), on the other hand, regsvr32
49 * calls DllInstall and then DllUnregisterServer as expected.
50 *
51 * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i").
52 * Without -n, DllRegisterServer called before DllInstall would mistakenly
53 * overwrite the default "PostgreSQL" event source registration.
54 */
55 if (bInstall)
57 return S_OK;
58}
STDAPI DllRegisterServer(void)
Definition: pgevent.c:65
static char event_source[256]
Definition: pgevent.c:25

References DllRegisterServer(), and event_source.

◆ DllMain()

BOOL WINAPI DllMain ( HANDLE  hModule,
DWORD  ul_reason_for_call,
LPVOID  lpReserved 
)

Definition at line 152 of file pgevent.c.

156{
157 if (ul_reason_for_call == DLL_PROCESS_ATTACH)
158 g_module = hModule;
159 return TRUE;
160}
static HANDLE g_module
Definition: pgevent.c:18

References g_module.

◆ DllRegisterServer()

STDAPI DllRegisterServer ( void  )

Definition at line 65 of file pgevent.c.

66{
67 HKEY key;
68 DWORD data;
69 char buffer[_MAX_PATH];
70 char key_name[400];
71
72 /* Set the name of DLL full path name. */
73 if (!GetModuleFileName((HMODULE) g_module, buffer, sizeof(buffer)))
74 {
75 MessageBox(NULL, "Could not retrieve DLL filename", "PostgreSQL error", MB_OK | MB_ICONSTOP);
76 return SELFREG_E_TYPELIB;
77 }
78
79 /*
80 * Add PostgreSQL source name as a subkey under the Application key in the
81 * EventLog registry key.
82 */
83 _snprintf(key_name, sizeof(key_name),
84 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
86 if (RegCreateKey(HKEY_LOCAL_MACHINE, key_name, &key))
87 {
88 MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
89 return SELFREG_E_TYPELIB;
90 }
91
92 /* Add the name to the EventMessageFile subkey. */
93 if (RegSetValueEx(key,
94 "EventMessageFile",
95 0,
96 REG_EXPAND_SZ,
97 (LPBYTE) buffer,
98 strlen(buffer) + 1))
99 {
100 MessageBox(NULL, "Could not set the event message file.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
101 return SELFREG_E_TYPELIB;
102 }
103
104 /* Set the supported event types in the TypesSupported subkey. */
105 data = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
106
107 if (RegSetValueEx(key,
108 "TypesSupported",
109 0,
110 REG_DWORD,
111 (LPBYTE) &data,
112 sizeof(DWORD)))
113 {
114 MessageBox(NULL, "Could not set the supported types.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
115 return SELFREG_E_TYPELIB;
116 }
117
118 RegCloseKey(key);
119 return S_OK;
120}
const void * data

References data, event_source, g_module, and sort-test::key.

Referenced by DllInstall().

◆ DllUnregisterServer()

STDAPI DllUnregisterServer ( void  )

Definition at line 127 of file pgevent.c.

128{
129 char key_name[400];
130
131 /*
132 * Remove PostgreSQL source name as a subkey under the Application key in
133 * the EventLog registry key.
134 */
135
136 _snprintf(key_name, sizeof(key_name),
137 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
139 if (RegDeleteKey(HKEY_LOCAL_MACHINE, key_name))
140 {
141 MessageBox(NULL, "Could not delete the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
142 return SELFREG_E_TYPELIB;
143 }
144 return S_OK;
145}

References event_source.

Variable Documentation

◆ event_source

char event_source[256] = DEFAULT_EVENT_SOURCE
static

Definition at line 25 of file pgevent.c.

Referenced by DllInstall(), DllRegisterServer(), and DllUnregisterServer().

◆ g_module

HANDLE g_module = NULL
static

Definition at line 18 of file pgevent.c.

Referenced by DllMain(), and DllRegisterServer().