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.");

    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.");

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];

  strcpy(tabCsteMsg[0] , "fichier1.txt");
  strcpy(tabCsteMsg[1] , "repertoire 1");
  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.


Who is Participating?
nietodConnect With a Mentor Commented:
You need to use an array of string pointers.  You are using an array of strings.

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.

try something like

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


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)
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

fannyrAuthor Commented:
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.

I don't undestand that.  Could you explain more carefully?
fannyrAuthor Commented:
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.
All Courses

From novice to tech pro — start learning today.