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.
fannyrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
You need to use an array of string pointers.  You are using an array of strings.

continues.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
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
0
nietodCommented:
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)
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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.

Fanny
0
nietodCommented:
I don't undestand that.  Could you explain more carefully?
0
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.



0
nietodCommented:
>> id of my category and not the value of the category
What does that mean.  I'm still not understanding you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.