Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 65975 Details for
Bug 146887
Clean up Reader.cpp Windows event log reader program
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Reader.cpp to address the memory leaking problem
Reader.cpp (text/plain), 22.86 KB, created by
Cindy Jin
on 2007-05-04 18:38:05 EDT
(
hide
)
Description:
Reader.cpp to address the memory leaking problem
Filename:
MIME Type:
Creator:
Cindy Jin
Created:
2007-05-04 18:38:05 EDT
Size:
22.86 KB
patch
obsolete
>/********************************************************************** > * Copyright (c) 2005, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * $Id: Reader.cpp,v 1.13 2007/04/27 17:25:24 dnsmith Exp $ > * > * Contributors: > * IBM - Initial implementation > **********************************************************************/ > > >#include <windows.h> >#include <stdlib.h> >#include <stdio.h> >#include <string.h> >#include <winerror.h> > >/*************************************************************************** > * Description: > * EvenLogReader receives the source Windows Event log name as a parameter > * and reads events from it using Windows EventLog API. The events are > * then transformed into strings and written to the standard output or > * optionally to a file whose name is passes as the second parameter. > * > ***************************************************************************/ > >const LPSTR cRecordNumberPref = "RecordNumber: "; >const LPSTR cEventTypePref = "Severity: "; >const LPSTR cCreationTimePref = "CreationTime: "; >const LPSTR cSourceComponentPref = "SourceComponent: "; >const LPSTR cEventCategoryPref = "EventCategory: "; >const LPSTR cEventIDPref = "EventID: "; >const LPSTR cUsernamePref = "Username: "; >const LPSTR cComputerNamePref = "Computername: "; >const LPSTR cLocationTypePref = "LocationType: "; >const LPSTR cLocationType = "Hostname"; >const LPSTR cMessagesPref = "Message: "; >const LPSTR cSeparatorToken = "@;@"; > >const LPSTR cErrorHeader = "<ACADErrorHeader>"; > >const int cbeDEBUG = 10; >const int cbeINFO = 20; >const int cbeWARN = 30; >const int cbeERROR = 40; >const int cbeFATAL = 50; > >const int MAX_MSG_LENGTH = 1024; > >/* bugzilla 143371 - maximum number of message strings in event record */ >const int MAX_MSG_STY = 21; > >FILE *fpOut = NULL; > >LPSTR GetDescriptionStringFromRegKey(EVENTLOGRECORD *pRecord, LPSTR source); >LPSTR getSourceName(EVENTLOGRECORD *record); >BOOL ReadEventSourceInfo(LPCSTR lpszESName, LPSTR lpszEvent); > >/* eventmessagefile handle > event description message index > Language ID of the message > Array of insertion strings */ >LPSTR GetEventMessage(HMODULE hDll, DWORD dwEventIndex, DWORD dwLanguageID, LPTSTR *lpInserts ); >bool isDigitNumber(char c); >LPSTR checkErrorCode(LPSTR lpMsgBuf); >LPSTR expandMsgBuffer(LPSTR msg, int size,int msgIndex); > >/** > * Set Event Severity based on EventType > */ >int getEventType(WORD ntEventType) >{ > int result = 0; > switch (ntEventType) > { > case (EVENTLOG_ERROR_TYPE): > result = cbeERROR; > break; > case (EVENTLOG_WARNING_TYPE): > result = cbeWARN; > break; > case (EVENTLOG_INFORMATION_TYPE): > result = cbeINFO; > break; > case (EVENTLOG_AUDIT_SUCCESS): > result = 15; > break; > case (EVENTLOG_AUDIT_FAILURE): > result = 16; > break; > default : > result = 17; > break; > } > > return result; >} > >void error(LPSTR errMessage) >{ > printf("%s\n%s\n", cErrorHeader, errMessage); >} > > >// removing carriage returns '\r' as well as line feeds '\n' >void removeNewLine(LPSTR str) >{ > for (int i=0; str[i] != '\0'; i++) > { > if (str[i] == '\n' || str[i] == '\r') > { > > str[i] = ' '; > } > } >} > >/** > *This method gets the EventLogRecord's discription text. > *It tries to get the message text based on the event source and event Id from the registered message file, > *if can't find the registered message file, message strings in the event record are displayed. > * > */ >void GetDescriptionString(LPSTR *pMessage, EVENTLOGRECORD *record) >{ > *pMessage = GetDescriptionStringFromRegKey(record, getSourceName(record)); > // the message retrieved contains the description text displayed in the Event Viewer > // we do not need to further get any messages. > if(*pMessage != NULL && strlen(*pMessage) > 2) > { > // remove if the string contains any new lines otherwise the adapter will fail. > removeNewLine(*pMessage); > return; > } > if(record->DataOffset == record->StringOffset) > { > return ; > } > > > // Since the description text could not be retrieved get the message strings > // recordString add a space character after a message string, so msgSize is equal to record message > // string size plus number of strings > DWORD msgSize = (record->DataOffset - record->StringOffset)+ record->NumStrings; > > *pMessage = (LPTSTR)LocalAlloc(LPTR,msgSize); > DWORD recordStringStart = (DWORD)record + record->StringOffset; > LPSTR recordString = (LPSTR)recordStringStart; > > // initialize the array to nulls > memset(*pMessage, NULL, msgSize); > > for (int i=0; i < record->NumStrings; i++) > { > removeNewLine(recordString); > strcat(*pMessage, recordString); > strcat(*pMessage, " "); > recordStringStart = recordStringStart + strlen(recordString) + 1; > recordString = (LPSTR)recordStringStart; > } >} > >/** > * Covert EventLogRecord from seconds to MM/dd/YYYY HH:MM:SS.ssssss format > */ >void copyTimeGenerated(LPSTR timeBuffer, PEVENTLOGRECORD pevlr) >{ > FILETIME FileTime, LocalFileTime; > SYSTEMTIME SysTime; > __int64 lgTemp; > __int64 SecsTo1970 = 116444736000000000; > > lgTemp = Int32x32To64(pevlr->TimeGenerated,10000000) + SecsTo1970; > > FileTime.dwLowDateTime = (DWORD) lgTemp; > FileTime.dwHighDateTime = (DWORD)(lgTemp >> 32); > > FileTimeToLocalFileTime(&FileTime, &LocalFileTime); > FileTimeToSystemTime(&LocalFileTime, &SysTime); > > sprintf(timeBuffer,"%02d/%02d/%02d %02d:%02d:%02d.%06d", > SysTime.wMonth, > SysTime.wDay, > SysTime.wYear, > SysTime.wHour, > SysTime.wMinute, > SysTime.wSecond, > SysTime.wMilliseconds); >} > >LPSTR getSourceName(EVENTLOGRECORD *record) >{ > return (LPSTR) ((LPSTR)record + sizeof(EVENTLOGRECORD)); >} > >LPSTR getComputerName(EVENTLOGRECORD *record) >{ > LPSTR sourceName = getSourceName(record); > return (LPSTR) (sourceName + strlen(sourceName) + 1); >} > >/** > * Get the user name from SID number > */ >void cpyUserName(LPSTR sidBuffer, DWORD sidLength, EVENTLOGRECORD *record) >{ > if (record->UserSidLength == 0) > { > strcpy(sidBuffer, "N/A"); > return; > } > > char referencedDomainName[500]; > DWORD domainLength = sizeof(referencedDomainName); > SID_NAME_USE eUse; > int res; > > res = LookupAccountSid( NULL, // [input] system name > (SID *)((LPSTR)record + record->UserSidOffset), // [input] the SID structure > sidBuffer, // [output] the buffer receiving the account name > &sidLength, // [input/output] the buffer length for the account name > referencedDomainName, // [output] domain name > &domainLength, // [input/output] the buffer length for the domain name > &eUse // [output] the type of the account > ); > if (res == 0) > { > strcpy(sidBuffer, "N/A"); > return; > } >} > >// writting EventLog event to the file and stand output >// In format of RecordNumber: Severity: CreationTime: SourceComponent: EventCategory: EventID: Username: Computername: LocationType: Message: >BOOL writeNextRecord(EVENTLOGRECORD *pevlr) >{ > LPSTR sourceName = getSourceName(pevlr);//get the SourceComponent value > LPSTR compName = getComputerName(pevlr);// get the ComputerName value > > const DWORD cUsernameSize = 500; > char username[cUsernameSize]; > DWORD userNameSize = cUsernameSize; > > cpyUserName(username, userNameSize, pevlr);//get UserName value > > LPSTR stringsBuffer = NULL; > > GetDescriptionString(&stringsBuffer, pevlr);//get Message value > if(stringsBuffer == NULL) > { > // using the LocalAlloc() to allocate memroy which is same as the FormatMessage() > stringsBuffer = (LPTSTR)LocalAlloc(LPTR,sizeof(char)); > strcpy(stringsBuffer , "\0" ); > } > > const DWORD cTimeSize = 500; > char time[cTimeSize]; > DWORD timeSize = cTimeSize; > > copyTimeGenerated(time, pevlr);//get CreationTime value > > int CBEseverity = getEventType(pevlr->EventType);//get Severity > > DWORD dwEventId = pevlr->EventID;//get EventID > DWORD dwMSB16Zeros = 65535; // this double word variable has its first 16 bits as zero and the remaining as 1 > dwEventId &= dwMSB16Zeros; > > if(printf("%s%d%s\t%s%d%s\t%s%s%s\t%s%s%s\t%s%d%s\t%s%6d%s\t%s%s%s\t%s%s%s\t%s%s%s\t%s%s%s\n" ,cRecordNumberPref, > pevlr->RecordNumber, cSeparatorToken,cEventTypePref, CBEseverity,cSeparatorToken, cCreationTimePref,time,cSeparatorToken, > cSourceComponentPref, (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)),cSeparatorToken, > cEventCategoryPref, pevlr->EventCategory,cSeparatorToken, cEventIDPref, dwEventId,cSeparatorToken, > cUsernamePref, username,cSeparatorToken, cComputerNamePref, compName, cSeparatorToken,cLocationTypePref, cLocationType,cSeparatorToken, > cMessagesPref, stringsBuffer,cSeparatorToken) < 0) > { > error("Failed to write event to output"); > LocalFree(stringsBuffer); > return FALSE; > } > > > if(fpOut) > { > if(fprintf(fpOut, "%s%d%s\t%s%d%s\t%s%s%s\t%s%s%s\t%s%d%s\t%s%6d%s\t%s%s%s\t%s%s%s\t%s%s%s\t%s%s%s\n" ,cRecordNumberPref, > pevlr->RecordNumber, cSeparatorToken,cEventTypePref, CBEseverity,cSeparatorToken, cCreationTimePref,time,cSeparatorToken, > cSourceComponentPref, (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)),cSeparatorToken, > cEventCategoryPref, pevlr->EventCategory,cSeparatorToken, cEventIDPref, dwEventId,cSeparatorToken, > cUsernamePref, username,cSeparatorToken, cComputerNamePref, compName, cSeparatorToken,cLocationTypePref, cLocationType,cSeparatorToken, > cMessagesPref, stringsBuffer,cSeparatorToken) < 0) > { > error("Failed to write event to output file"); > LocalFree( stringsBuffer); > return FALSE; > } > _flushall( ); > } > LocalFree(stringsBuffer); > > > return TRUE; >} > >void main(int argc , char * argv[] ) >{ > const DWORD cBufferSize = 500; > HANDLE hLog; > EVENTLOGRECORD *pevlr = NULL; > > DWORD dwRead, dwNeeded; > > > > if(argc < 2) > { > error("Usage: EventLogReader.exe logName <outputFilename>"); > return; > } > > fpOut = fopen(argv[2], "w"); > if(!fpOut) > { > //error("Failed to open output file"); > //return; > } > > // creating event which will be signaled by the the EventLog > HANDLE hEvent = CreateEvent( > NULL, > FALSE, // reset type > FALSE, // initial state > NULL // object name > ); > > if(hEvent == NULL) > { > error("Failed to create event"); > return; > } > > // Open the Application event log. > hLog = OpenEventLog( NULL, // use local computer > argv[1]); // source name > > if (hLog == NULL) > { > error("Failed to open event log"); > return; > } > > // subscribing to the events of new entries to the event log > if(!NotifyChangeEventLog(hLog, hEvent)) > { > error("FAILED to subscribe for notifications"); > return; > } > > char one[1]; > LPSTR buffer = NULL; > > //while(1) > { > > while (1) > { > // dummy read to get the size of 1 EventLog entry. > if(!ReadEventLog(hLog, > EVENTLOG_SEQUENTIAL_READ|EVENTLOG_FORWARDS_READ, > 0, > (LPVOID)one, > 1, > &dwRead, > &dwNeeded)) > > { > HRESULT hr = GetLastError(); > if(hr == ERROR_HANDLE_EOF) > { > CloseEventLog(hLog); > //break; > if(fpOut) > fclose(fpOut); > return; > } > > if(hr != ERROR_INSUFFICIENT_BUFFER) > { > error("Failed to read EventLog entry"); > CloseEventLog(hLog); > if(fpOut) > fclose(fpOut); > return; > } > } > > buffer = new char[dwNeeded]; > DWORD temp = dwNeeded; > if (buffer == NULL) { > printf("cannot allocate memory"); > CloseEventLog(hLog); > //break; > if(fpOut) > fclose(fpOut); > return; > } > > //reading 1 entry from the event log > if(!ReadEventLog(hLog, // event log handle > EVENTLOG_SEQUENTIAL_READ|EVENTLOG_FORWARDS_READ, // sequential read > 0, // ignored for sequential reads > (LPVOID)buffer, // address of buffer for read data > temp, // size of buffer > &dwRead, // number of bytes read > &dwNeeded)) // bytes in next record > { > HRESULT hr = GetLastError(); > delete []buffer; > error("Failed to read EventLog entry"); > CloseEventLog(hLog); > if(fpOut) > fclose(fpOut); > return; > } > > pevlr = (EVENTLOGRECORD *) buffer; > > if(!writeNextRecord(pevlr)) > { > delete []buffer; > CloseEventLog(hLog); > if(fpOut) > fclose(fpOut); > return; > } > delete []buffer; > } > > // wait for EventLog notification >// WaitForSingleObject(hEvent, INFINITE); > } > > CloseEventLog(hLog); > if(fpOut) > fclose(fpOut); >} > > >/** > * It gets the message text for event log reocrd with its source from the registered message file, > * Then it uses LoadLibraryEx function to load the message file. Finally it uses the FormatMessage function to > * get the base description string from the loaded module and replaces the insertion parameters in the > * base description string to yield the final message string. > */ > >LPSTR GetDescriptionStringFromRegKey(EVENTLOGRECORD *pRecord, LPSTR source) >{ > BOOL bResult; > TCHAR szEvent[256],szBuffer[256], **first_sz; > HMODULE hEvt; > LPTSTR lpP2[MAX_MSG_STY]; /* array for event strings - hardcoded size - bugzilla 143371 */ > LPTSTR * lpP = lpP2; > LPSTR lpBuf = NULL; > LPTSTR lpstrlpBuf = ""; > LPSTR pStr = NULL; > int newArrayFlag = 0; /* flag to indicate new array was allocated - bugzilla 143371/146747 */ > > if (pRecord->NumStrings ) > { > /* bugzilla 143371/146747 - allocate new larger array to accommodate some event records on 64-bit systems */ > if(pRecord->NumStrings > MAX_MSG_STY) > { > lpP = new LPTSTR[pRecord->NumStrings]; > newArrayFlag = 1; > } > > pStr = (LPSTR)((LPBYTE)pRecord + pRecord->StringOffset); > } > else > { > pStr = ""; > } > > if ( pStr ) > { > DWORD i; > for ( i = 0; i < pRecord->NumStrings; i++ ) > { > lpP[i] = (LPSTR)pStr; > pStr = strchr( (LPSTR)pStr, '\0' ) + 1; > } > } > //Get the file name(s) from the registry > bResult = ReadEventSourceInfo( source, szEvent); > if(strchr(szEvent, ';')) > { > int i=0, j, k, num_files=0, last=0; > LPSTR aux, cad; > aux = szEvent; > while(aux = strchr(aux, ';')) > { > num_files++; > aux++; > } > aux = szEvent; > > for(j=0; j<= num_files + 1; j++) > { > int counter =0; > while((szEvent[i] != ';' && szEvent[i] != '\0') && i ) > { > i++; > counter++; > } > > if(szEvent[i] == ';' || szEvent[i] == '\0') > { > counter++; > i++; > } > > > first_sz= (TCHAR **)malloc(num_files * (sizeof(szEvent))); > cad = (LPSTR) malloc(counter+1); > > // get the first file name > for(k = 0; k < counter; k++ ) > { > cad[k] = szEvent[last+k]; > } > cad[k]= '\0'; > > last = i; > i++; > > if(k == 0) > { > continue; > } > > first_sz[j] = cad; > //Replace the %SystemRoot% kind of environment variables with their values > ExpandEnvironmentStrings(first_sz[j],szBuffer, 257); > > // Load the EventMessageFile, could be an .exe or .dll > hEvt = LoadLibraryEx(szBuffer, NULL, DONT_RESOLVE_DLL_REFERENCES ); > > /* Load the event message file DLL */ > if ( hEvt ) > { > /* Get the event message with the paramater strings inserted */ > lpBuf = GetEventMessage( hEvt, pRecord->EventID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), lpP ); > FreeLibrary( hEvt ); // unload event message file > } > > free(first_sz); > free(cad); > > if(lpBuf != NULL && strlen(lpBuf) > 0) > { > break; > } > } > /* bugzilla 143371/146747 - if a new array was allocated then free it */ > if (newArrayFlag == 1) { > delete []lpP; > } > return (lpBuf); > } > else // single EventMesssageFile found > { > ExpandEnvironmentStrings(szEvent, szBuffer, 257); > hEvt = LoadLibraryEx(szBuffer, NULL, DONT_RESOLVE_DLL_REFERENCES ); > /* Load the event message file DLL */ > if ( hEvt ) > { > /* Get the event message with the paramater strings inserted */ > lpBuf = GetEventMessage( hEvt, pRecord->EventID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), lpP ); > FreeLibrary( hEvt ); > } > } > > /* bugzilla 143371/146747 - if a new array was allocated then free it */ > if (newArrayFlag == 1) { > delete []lpP; > } > return (lpBuf); >} > >// Get the name of the file that contains the message text for the event >BOOL ReadEventSourceInfo(LPCSTR lpszESName, LPSTR lpszEvent) >{ > BOOL bResult = FALSE; > HKEY hKey; > DWORD dwBytesReturned; > TCHAR szKeyName[128]; > > /* search for event source registry key */ > lstrcpy( szKeyName, "System\\CurrentControlSet\\Services\\EventLog\\Security\\" ); > lstrcat( szKeyName, lpszESName ); > if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hKey ) != ERROR_SUCCESS ) > { > lstrcpy( szKeyName, "System\\CurrentControlSet\\Services\\EventLog\\System\\" ); > lstrcat( szKeyName, lpszESName ); > RegCloseKey(hKey); > if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hKey ) != ERROR_SUCCESS ) > { > lstrcpy( szKeyName, "System\\CurrentControlSet\\Services\\EventLog\\application\\" ); > lstrcat( szKeyName, lpszESName ); > RegCloseKey(hKey); > if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hKey ) != ERROR_SUCCESS ) > { > /* The registry key of event source is not found, so message cannot be retrieved. > Things like this are generally encountered when the application that wrote the event to > windows events is uninstalled. > */ > RegCloseKey(hKey); > return FALSE; > } > } > } > > bResult = TRUE; /* Found the registered event source key */ > > /* Get the EventMessageFile path */ > dwBytesReturned = MAX_PATH; // max length of the file path in Windows > if ( RegQueryValueEx( hKey, "EventMessageFile", NULL, NULL, (LPBYTE)lpszEvent, &dwBytesReturned ) != ERROR_SUCCESS ) > { > lpszEvent[0] = '\0'; > } > > RegCloseKey(hKey); > return( bResult ); >} > >/** > * uses the FormatMessage function to get the base description string from the loaded module and replaces the insertion parameters in the > * base description string to yield the final message string. > */ >LPSTR GetEventMessage(HMODULE hDll, DWORD dwEventIndex, DWORD dwLanguageID, LPTSTR *lpInserts ) >{ > DWORD dwReturn; > LPSTR lpMsgBuf = NULL; > LPSTR tmpMsg = NULL; > DWORD dwFlags = FORMAT_MESSAGE_FROM_HMODULE |FORMAT_MESSAGE_ALLOCATE_BUFFER; > > if ( lpInserts ) > { > dwFlags |= FORMAT_MESSAGE_ARGUMENT_ARRAY; > } > > dwReturn = FormatMessage(dwFlags, hDll, dwEventIndex, dwLanguageID, (LPTSTR) &lpMsgBuf, 0, lpInserts ); > if(dwReturn == 0) // message could not be retrieved > { > return NULL; > } > > //check if it contains "%%" string, which may indicate an error code. > lpMsgBuf = checkErrorCode(lpMsgBuf); > if(lpMsgBuf != tmpMsg) > { > //it allocats memory in checkErrorCode to copy all lpMsgBuf to the new memory > //remove the memory after. > LocalFree(tmpMsg); > } > > > return( lpMsgBuf ); >} > >bool isDigitNumber(char c) >{ > if(c -'0' >=0 && '9'-c>=0) > { > return true; > } > return false; >} > >//This function is used to check if there is a system error code which if format of "%%0123456789" for the event message, if yes, it is going to replace >//the system error code with the system error message. > >LPSTR checkErrorCode(LPSTR lpMsgBuf) >{ > if(strstr(lpMsgBuf,"%%") == NULL) > { > return lpMsgBuf; > } > > LPSTR subStr = NULL; > DWORD returnMsgSize = 500; > DWORD returnMsgIndex = 0; > LPSTR returnMsg = (LPTSTR)LocalAlloc(LPTR,returnMsgSize); > > > // Iterate over the message buffer looking for %% followed by digits > for(DWORD i=0; i<strlen(lpMsgBuf); i++) > { > if(lpMsgBuf[i]=='%' && lpMsgBuf[i+1]=='%') > { > // %% was found so look for digits immediately after it > DWORD starIndex = i+2; > DWORD tmpIndex = i+2; > //get the error number > while(isDigitNumber(lpMsgBuf[tmpIndex])) > { > tmpIndex++; > } > > // If %%dddddd was found then get the digit portion and > // use it to get the corresponding system error message. > if(tmpIndex > starIndex) > { > LPSTR digitStr = new char[tmpIndex-starIndex+1]; > for(DWORD j=starIndex;j<tmpIndex;j++) > { > > digitStr[j-starIndex]=lpMsgBuf[j]; > > } > digitStr[tmpIndex-starIndex] ='\0'; > //convert the error number string to int > DWORD msgId = atoi(digitStr); > delete []digitStr; > > LPSTR errorMsg = NULL; > // get the error message; > FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, > NULL, > msgId, > 0,// Default language > (LPTSTR) &errorMsg, > 0, > NULL ); > if(errorMsg != NULL) > { > // Add the system error message to the return message > bool expandBuffer =( (returnMsgIndex+strlen(errorMsg))>=returnMsgSize); > //if the message length is bigger than the size of buffer, expands it. > if(expandBuffer) > { > LPSTR tmpMsg = returnMsg; > returnMsgSize = 2*returnMsgSize+strlen(errorMsg); > returnMsg = expandMsgBuffer(returnMsg,returnMsgSize,returnMsgIndex); > LocalFree(tmpMsg); > > } > returnMsg[returnMsgIndex++] ='\0'; > strcat(returnMsg,errorMsg); > LocalFree(errorMsg); > i=tmpIndex-1; > returnMsgIndex = strlen(returnMsg); > // Loop back to continue searching for another embedded error code in the message > continue; > } > } > } > > // %%dddddd or the error code message was not found so copy the next character into the > // return buffer and loop back to continue searching. > > //if the message length is bigger than the size of buffer, expands it. > if(returnMsgIndex>=returnMsgSize) > { > LPSTR tmpMsg = returnMsg; > returnMsgSize = 2*returnMsgSize; > returnMsg = expandMsgBuffer(returnMsg,returnMsgSize,returnMsgIndex); > LocalFree(tmpMsg); > > > } > returnMsg[returnMsgIndex++]=lpMsgBuf[i]; > > } > //if the message length is bigger than the size of buffer, expands it. > if(returnMsgIndex>=returnMsgSize) > { > LPSTR tmpMsg = returnMsg; > returnMsgSize = 2*returnMsgSize; > returnMsg = expandMsgBuffer(returnMsg,returnMsgSize,returnMsgIndex); > LocalFree(tmpMsg); > > > } > //add the end of string char > returnMsg[returnMsgIndex++]='\0'; > > return returnMsg; > > >} > >LPSTR expandMsgBuffer(LPSTR msg, int size,int msgIndex) >{ > > LPSTR tmpMsg = (LPTSTR)LocalAlloc(LPTR,size); > strncpy(tmpMsg,msg,msgIndex); > > return tmpMsg; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 146887
:
65822
| 65975