Sunteți pe pagina 1din 3

#pragma code ("kernel32.

dll")
void GetLocalTime( LPSYSTEMTIME lpSystemTime);
BOOL GetComputerNameA(LPSTR Computername, LPDWORD size);
#pragma code()
#ifndef RUN_ON_WEBNAVIGATOR
#pragma code ("useadmin.dll")
BOOL PWRTGetCurrentUser (LPTSTR dest, int bufsize );
#pragma code()
#endif
int ISALG_OperationLog( long* psMsgNumber,
char* pszSource,
char* pszArea,
char* pszEvent,
char* pszBatch,
char* pszUnit,
double fOld,
double fNew,
char* pszComment )
{
MSG_RTDATA_INSTANCECOMMENT_STRUCT MsgCreateEx;
CMN_ERROR scError;
int iRet= FALSE;
DWORD dwServiceID = 0;
BOOL bOK;
SYSTEMTIME time;
DWORD dwBufSize = 256;
BOOL Web;
char szComputerName[256]= "";
char szSource[256] = "";
char szUnit[256] = "";
char szEvent[256] = "";
char szBatch[256] = "";
char szUser[256] = "";
char *szNoUser ;
char *szWebUser = "";
//======================================
// INIT_MESSAGE_STRUCT
//======================================
memset(&MsgCreateEx,0,sizeof(MsgCreateEx));
memset(&scError,0,sizeof(scError));
GetLocalTime(&time);
MsgCreateEx.stMsgTime = time;
MsgCreateEx.dwMsgNr = *psMsgNumber; // Message Numbe
r; (default=12508141)
MsgCreateEx.wPValueUsed = (WORD)(0x0000 ); // no real process value used
MsgCreateEx.wTextValueUsed = 0x001F; // text values 1 .. 5 us
ed for textblocks 1 .. 5
MsgCreateEx.dwFlags = MSG_FLAG_COMMENT | MSG_FLAG_TEXTVALUES;
MsgCreateEx.dwMsgState = MSG_STATE_COME;
if ( pszComment != NULL) {
strncpy(MsgCreateEx.szComment, pszComment, sizeof (MsgCreateEx.szComment
) - 1);
}
if(pszUnit != NULL){
strncpy(szUnit, pszUnit, sizeof (szUnit) - 1);
}
// replasce username, if not availble (below Web Navigator V7.0)
// Get user-name
#ifdef RUN_ON_WEBNAVIGATOR
szWebUser = GetTagChar("@NOTP::@CurrentUser");
szNoUser = "--- unknown web-user ---";
#else
PWRTGetCurrentUser (szUser, sizeof (szUser));
szNoUser = "--- unknown user ---";
#endif
// replace username, if not availble (below Web Navigator V7.0)
if (strlen(szUser) > 1){
strncpy (MsgCreateEx.szUser, szUser, 15 ); // 16 character - E
ndsign ('\0')
}
else {
// strncpy (MsgCreateEx.szUser, szNoUser, strlen(szNoUser));
strncpy (MsgCreateEx.szUser, szNoUser, 15); // 16 character - En
dsign ('\0')
}
GetComputerNameA(szComputerName, &dwBufSize);
strncpy (MsgCreateEx.szComputerName, szComputerName, 15);
if (pszSource!= NULL) {
strncpy (szSource, pszSource, sizeof (szSource) - 1);
strncpy ( MsgCreateEx.szInstance, pszSource, sizeof (MsgCreateEx.szInsta
nce) - 1);
strncpy ( MsgCreateEx.mtTextValue[0].szText, szSource, sizeof (MsgCreate
Ex.mtTextValue[0].szText) - 1);
}
if (pszArea!= NULL) {
strncpy ( MsgCreateEx.mtTextValue[1].szText, pszArea, sizeof (MsgCreateE
x.mtTextValue[1].szText) - 1);
}
if (pszEvent!= NULL){
sprintf (szEvent, "%s\\%s: %s new=%.3f old=%.3f [%s]" , szComputerNa
me, MsgCreateEx.szUser, pszEvent, fNew, fOld, szUnit);
strncpy (MsgCreateEx.mtTextValue[2].szText, szEvent, sizeof (MsgCreateE
x.mtTextValue[2].szText) -1);
strncpy (MsgCreateEx.mtTextValue[4].szText, szEvent, sizeof (MsgCreateE
x.mtTextValue[4].szText) -1);
}
if (pszBatch != NULL){
strncpy (szBatch, pszBatch , sizeof (szBatch) - 1);
strncpy (MsgCreateEx.mtTextValue[3].szText, szBatch, sizeof (MsgCreateE
x.mtTextValue[3].szText) -1);
}
printf ("#I201: ISALG_OperationLog() - szSource=\"%s\" szEvent=\"%s\"\
r\n", szSource, szEvent);
printf ("MsgCreateEx.szUser: >%s<\r\n", MsgCreateEx.szUser);
printf ("MsgCreateEx.szComputerName: >%s<\r\n", MsgCreateEx.szComputerNa
me);
//======================================
// START_MESSAGE_SERVICE
//======================================
bOK= MSRTStartMsgService( &dwServiceID, NULL, NULL, (DWORD)0, NULL, NU
LL);
if (bOK == FALSE){
printf("#E101: ISALG_OperationLog() - Unable to start message service!")
;
return (-101);
}
//======================================
// CREATE_MESSAGE_INSTANCE
//======================================
bOK = MSRTCreateMsgInstanceWithComment(dwServiceID, &MsgCreateEx, &scError) ;
//Create Message
if(bOK == FALSE){
printf ("#E301: ISALG_OperationLog() - Error at MSRTCreateMsg() szErrorText=
\"%s\"\r\n", scError.szErrorText);
iRet = -301;
}
//======================================
// STOP_MESSAGE_SERVICE
//======================================
bOK= MSRTStopMsgService( dwServiceID, &scError);
return (iRet);
}

S-ar putea să vă placă și