Link to home
Start Free TrialLog in
Avatar of fannyr
fannyr

asked on

Record in The NT EventLog a message with 2 inserting strings

Hello ,

I want to write in the NT EventLog a message with 2 strings to merge with the message.
I've written the code using VC++ 5.0 in NT 4 as follow :


#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <tchar.h>

#include "uniporc.h"

/*------------------------------------------------------------------*/
/*      PROTOTYPES                                                                    */
/*------------------------------------------------------------------*/

void EcrireEventLog1(char * , char **, WORD, WORD, WORD, WORD);

void EcrireEventLog1(char *szEventSource,char **szMsg, WORD wTypeError, WORD wCategory,  WORD wMessageId, WORD wNbStringsInsert)
{
    HANDLE h;
 
    h = RegisterEventSource(NULL,  // uses local computer
             szEventSource);          // source name
    if (h == NULL)
      {
        printf("Could not register the event source.");
            exit(-1);
      }

    if (!ReportEvent(h,           // event log handle
            wTypeError,  // event type
            wCategory,                    // category zero si aucune categorie
            wMessageId,        // event identifier
            NULL,                 // no user security identifier
            wNbStringsInsert,                    // number of substitutions strings
            0,                    // no data
            (LPCTSTR *) &szMsg,     // pointer to substitution string array
            NULL))                // pointer to data
      {
        printf("Could not report the event.");
            exit(-1);
      }
 
    DeregisterEventSource(h);
}

void main (void)
{

  char EventSource[25];
  WORD m_wTypeError;
  WORD m_wCategory;  
  WORD m_wMessageId;
  WORD m_wNbStringsInsert;
  char strMsg[25];
  char **tabMsg;
  char tabCsteMsg[2][25];

  memset(EventSource,'\0',sizeof(EventSource));
  sprintf(EventSource,"uniporc");
 
  strcpy(tabCsteMsg[0] , "fichier1.txt");
  strcpy(tabCsteMsg[1] , "repertoire 1");
 
  m_wTypeError = EVENTLOG_ERROR_TYPE;
  m_wCategory = CAT_UNPURGE;
  m_wMessageId = MC_TEST2;
  m_wNbStringsInsert = 2;

 
  EcrireEventLog1(EventSource,tabCsteMsg, m_wTypeError, m_wCategory,  m_wMessageId, m_wNbStringsInsert);

}




The first string is merged with the message but not the second string.
Does any suggestion or advice for me?

Thank you for your attention.

Regards.

Fanny.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

You store the strings in a 2D array like

>> char tabCsteMsg[2][25];

this is an array of characters for the 1 string followed by another array of characters for the 2nd string.  That is not what the ReportEvent() function requires.  It needs you to pass a pointer to an array.  This array is an array of pointers to the strings to be used.  That is, it needs a pointer to an array of string pointers.

continues
try something like

const char Msg1[] =  "fichier1.txt";
const char Msg2[] =  "repertoire 1";
const char *tabCsteMsg[2] = {&Msg1,&Msg2};

or

const char *Msg1 =  "fichier1.txt";
const char *Msg2 =  "repertoire 1";
const char *tabCsteMsg[2] = {Msg1,Msg2};

Or more suscinctly, just

const char *tabCsteMsg[2] = {"fichier1.txt", "repertoire 1"};

(They all will work, just different options)
Avatar of fannyr

ASKER

thanks a lot for the answer.
I have an another problem for the Category , the EventViewer shows (1) rather "Traitement1".
The category message file and Event message file are the same file.
meanwhile I close and restart EventViewer.

Thank you for your attention.

Fanny
I don't undestand that.  Could you explain more carefully?
Avatar of fannyr

ASKER

The event identifiers and categories are stored in the EventMessageFile and the CategoryMessageFile. This files are the same file for my event source.

When a message was written in the Event Log by my EventSource, under the column Category is displayed the id of my category and not the value of the category.



>> id of my category and not the value of the category
What does that mean.  I'm still not understanding you.