Skip to main content
Inspiring
Jul 7, 2023 1:28 PM UTC
Question

C++ Windows - posting to application event log

Is there anything special that needs to be done to post to the Windows Applicationevent log? Using some boilerplate code that doesn't get any error, but not seeing anything in the log.

I had to set up the policy.txt file to allow file access and to run an external application, but didn't see anything in the docs about event log access.

This topic is closed to new replies. Start a new post to keep the conversation going.

9 replies

Inspiring
Jul 7, 2023 2:26 PM UTC

Actually, I was mistaken; it is getting access denied.

Translate
Inspiring
Jul 7, 2023 2:44 PM UTC

code below. The handle returned from OpenEventLog is NULL and GetLastError returns 5, which is access denied. 

 
DWORD dwLastError = 0;
int PostToEventLog(string sMessage, bool bErr)
{
    HANDLE hHandle = OpenEventLog(NULL, "Application");
 
    if (NULL != hHandle)
    {
        int eventtype;
        if (bErr)
            eventtype = EVENTLOG_ERROR_TYPE;
        else
            eventtype = EVENTLOG_SUCCESS;
        if (!ReportEvent(hHandle, eventtype, 0, 0, NULL, 1, 0, (LPCTSTR *)sMessage.c_str(), NULL))
        {
            return -1;
        }
CloseEventLog(hHandle);
    }
else
{
dwLastError = GetLastError();
return (int)dwLastError;
}
    return 0;
}
 
Translate
Thom Parker
Community Expert
Community Expert
Jul 7, 2023 4:28 PM UTC

This is an Acrobat Developer forum. Are you running this code from within an Acrobat Plug-in?  

If not, then you are in the wrong place. 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often