postgresql/src/bin/pgevent/pgevent.c

120 lines
2.9 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* pgevent.c
* Defines the entry point for pgevent dll.
2004-08-29 07:07:03 +02:00
* The DLL defines event source for backend
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pgevent/pgevent.c,v 1.3 2004/08/30 02:54:40 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "windows.h"
#include "olectl.h"
#include "string.h"
/* Global variables */
2004-08-29 07:07:03 +02:00
HANDLE g_module = NULL; /* hModule of DLL */
/* Prototypes */
2004-08-29 07:07:03 +02:00
STDAPI
DllRegisterServer(void);
STDAPI DllUnregisterServer(void);
BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
/*
2004-08-29 07:07:03 +02:00
* DllRegisterServer --- Instructs DLL to create its registry entries
*/
2004-08-29 07:07:03 +02:00
STDAPI
DllRegisterServer(void)
{
2004-08-29 07:07:03 +02:00
HKEY key;
DWORD data;
char buffer[_MAX_PATH];
2004-08-29 07:07:03 +02:00
/* Set the name of DLL full path name. */
if (!GetModuleFileName((HMODULE) g_module, buffer, sizeof(buffer)))
{
2004-08-29 07:07:03 +02:00
MessageBox(NULL, "Could not retrieve DLL filename", "PostgreSQL error", MB_OK | MB_ICONSTOP);
return SELFREG_E_TYPELIB;
}
2004-08-29 07:07:03 +02:00
/*
* Add PostgreSQL source name as a subkey under the Application key in
* the EventLog registry key.
*/
if (RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\PostgreSQL", &key))
{
2004-08-29 07:07:03 +02:00
MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
return SELFREG_E_TYPELIB;
}
2004-08-29 07:07:03 +02:00
/* Add the name to the EventMessageFile subkey. */
if (RegSetValueEx(key,
"EventMessageFile",
0,
REG_EXPAND_SZ,
(LPBYTE) buffer,
strlen(buffer) + 1))
{
2004-08-29 07:07:03 +02:00
MessageBox(NULL, "Could not set the event message file.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
return SELFREG_E_TYPELIB;
}
2004-08-29 07:07:03 +02:00
/* Set the supported event types in the TypesSupported subkey. */
data = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
if (RegSetValueEx(key,
"TypesSupported",
0,
REG_DWORD,
(LPBYTE) & data,
sizeof(DWORD)))
{
2004-08-29 07:07:03 +02:00
MessageBox(NULL, "Could not set the supported types.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
return SELFREG_E_TYPELIB;
}
2004-08-29 07:07:03 +02:00
RegCloseKey(key);
return S_OK;
}
/*
* DllUnregisterServer --- Instructs DLL to remove only those entries created through DllRegisterServer
*/
2004-08-29 07:07:03 +02:00
STDAPI
DllUnregisterServer(void)
{
2004-08-29 07:07:03 +02:00
/*
* Remove PostgreSQL source name as a subkey under the Application key
* in the EventLog registry key.
*/
if (RegDeleteKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\PostgreSQL"))
{
2004-08-29 07:07:03 +02:00
MessageBox(NULL, "Could not delete the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
return SELFREG_E_TYPELIB;
}
return S_OK;
}
/*
* DllMain --- is an optional entry point into a DLL.
*/
BOOL WINAPI
2004-08-29 07:07:03 +02:00
DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
2004-08-29 07:07:03 +02:00
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
g_module = hModule;
2004-08-29 07:07:03 +02:00
return TRUE;
}