Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

pgevent.c File Reference

#include <windows.h>
#include <olectl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.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

HANDLE g_module = NULL
char event_source [256] = "PostgreSQL"

Function Documentation

HRESULT DllInstall ( BOOL  bInstall,
LPCWSTR  pszCmdLine 
)

Definition at line 42 of file pgevent.c.

References DllRegisterServer(), and event_source.

{

    if (pszCmdLine && *pszCmdLine != '\0')
        wcstombs(event_source, pszCmdLine, sizeof(event_source));

    /*
     * This is an ugly hack due to the strange behavior of "regsvr32 /i".
     *
     * When installing, regsvr32 calls DllRegisterServer before DllInstall.
     * When uninstalling (i.e. "regsvr32 /u /i"), on the other hand, regsvr32
     * calls DllInstall and then DllUnregisterServer as expected.
     *
     * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i").
     * Without -n, DllRegisterServer called before DllInstall would mistakenly
     * overwrite the default "PostgreSQL" event source registration.
     */
    if (bInstall)
        DllRegisterServer();
    return S_OK;
}

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

Definition at line 157 of file pgevent.c.

References g_module.

{
    if (ul_reason_for_call == DLL_PROCESS_ATTACH)
        g_module = hModule;
    return TRUE;
}

STDAPI DllRegisterServer ( void   ) 

Definition at line 70 of file pgevent.c.

References event_source, g_module, and NULL.

Referenced by DllInstall().

{
    HKEY        key;
    DWORD       data;
    char        buffer[_MAX_PATH];
    char        key_name[400];

    /* Set the name of DLL full path name. */
    if (!GetModuleFileName((HMODULE) g_module, buffer, sizeof(buffer)))
    {
        MessageBox(NULL, "Could not retrieve DLL filename", "PostgreSQL error", MB_OK | MB_ICONSTOP);
        return SELFREG_E_TYPELIB;
    }

    /*
     * Add PostgreSQL source name as a subkey under the Application key in the
     * EventLog registry key.
     */
    _snprintf(key_name, sizeof(key_name),
            "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
              event_source);
    if (RegCreateKey(HKEY_LOCAL_MACHINE, key_name, &key))
    {
        MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
        return SELFREG_E_TYPELIB;
    }

    /* Add the name to the EventMessageFile subkey. */
    if (RegSetValueEx(key,
                      "EventMessageFile",
                      0,
                      REG_EXPAND_SZ,
                      (LPBYTE) buffer,
                      strlen(buffer) + 1))
    {
        MessageBox(NULL, "Could not set the event message file.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
        return SELFREG_E_TYPELIB;
    }

    /* 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)))
    {
        MessageBox(NULL, "Could not set the supported types.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
        return SELFREG_E_TYPELIB;
    }

    RegCloseKey(key);
    return S_OK;
}

STDAPI DllUnregisterServer ( void   ) 

Definition at line 132 of file pgevent.c.

References event_source, and NULL.

{
    char        key_name[400];

    /*
     * Remove PostgreSQL source name as a subkey under the Application key in
     * the EventLog registry key.
     */

    _snprintf(key_name, sizeof(key_name),
            "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
              event_source);
    if (RegDeleteKey(HKEY_LOCAL_MACHINE, key_name))
    {
        MessageBox(NULL, "Could not delete the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
        return SELFREG_E_TYPELIB;
    }
    return S_OK;
}


Variable Documentation

char event_source[256] = "PostgreSQL"

Definition at line 29 of file pgevent.c.

HANDLE g_module = NULL

Definition at line 22 of file pgevent.c.

Referenced by DllMain(), and DllRegisterServer().