|
Lines 12-17
Link Here
|
| 12 |
|
12 |
|
| 13 |
|
13 |
|
| 14 |
#include <windows.h> |
14 |
#include <windows.h> |
|
|
15 |
#include <stdlib.h> |
| 15 |
#include <stdio.h> |
16 |
#include <stdio.h> |
| 16 |
#include <string.h> |
17 |
#include <string.h> |
| 17 |
#include <winerror.h> |
18 |
#include <winerror.h> |
|
Lines 62-69
Link Here
|
| 62 |
Language ID of the message |
63 |
Language ID of the message |
| 63 |
Array of insertion strings */ |
64 |
Array of insertion strings */ |
| 64 |
LPSTR GetEventMessage(HMODULE hDll, DWORD dwEventIndex, DWORD dwLanguageID, LPTSTR *lpInserts ); |
65 |
LPSTR GetEventMessage(HMODULE hDll, DWORD dwEventIndex, DWORD dwLanguageID, LPTSTR *lpInserts ); |
| 65 |
|
66 |
bool isDigitNumber(char c); |
| 66 |
|
67 |
LPSTR checkErrorCode(LPSTR lpMsgBuf); |
| 67 |
int getEventType(WORD ntEventType) |
68 |
int getEventType(WORD ntEventType) |
| 68 |
{ |
69 |
{ |
| 69 |
int result = 0; |
70 |
int result = 0; |
|
Lines 589-594
Link Here
|
| 589 |
{ |
590 |
{ |
| 590 |
DWORD dwReturn; |
591 |
DWORD dwReturn; |
| 591 |
LPSTR lpMsgBuf = NULL; |
592 |
LPSTR lpMsgBuf = NULL; |
|
|
593 |
LPSTR tmpMsg = NULL; |
| 592 |
DWORD dwFlags = FORMAT_MESSAGE_FROM_HMODULE |FORMAT_MESSAGE_ALLOCATE_BUFFER; |
594 |
DWORD dwFlags = FORMAT_MESSAGE_FROM_HMODULE |FORMAT_MESSAGE_ALLOCATE_BUFFER; |
| 593 |
|
595 |
|
| 594 |
if ( lpInserts ) |
596 |
if ( lpInserts ) |
|
Lines 598-607
Link Here
|
| 598 |
|
600 |
|
| 599 |
dwReturn = FormatMessage(dwFlags, hDll, dwEventIndex, dwLanguageID, (LPTSTR) &lpMsgBuf, 0, lpInserts ); |
601 |
dwReturn = FormatMessage(dwFlags, hDll, dwEventIndex, dwLanguageID, (LPTSTR) &lpMsgBuf, 0, lpInserts ); |
| 600 |
if(dwReturn == 0) // message could not be retrieved |
602 |
if(dwReturn == 0) // message could not be retrieved |
| 601 |
{ |
603 |
{ |
| 602 |
return NULL; |
604 |
|
|
|
605 |
return NULL; |
| 603 |
} |
606 |
} |
| 604 |
|
607 |
|
|
|
608 |
//check if there is system error message |
| 609 |
|
| 610 |
do |
| 611 |
{ |
| 612 |
tmpMsg = lpMsgBuf; |
| 613 |
lpMsgBuf = checkErrorCode(lpMsgBuf); |
| 614 |
|
| 615 |
}while((strcmp(tmpMsg,lpMsgBuf) != 0)); |
| 616 |
|
| 605 |
return( lpMsgBuf ); |
617 |
return( lpMsgBuf ); |
| 606 |
} |
618 |
} |
| 607 |
|
619 |
|
|
|
620 |
bool isDigitNumber(char c) |
| 621 |
{ |
| 622 |
if(c -'0' >=0 && '9'-c>=0) |
| 623 |
{ |
| 624 |
return true; |
| 625 |
} |
| 626 |
return false; |
| 627 |
} |
| 628 |
LPSTR checkErrorCode(LPSTR lpMsgBuf) |
| 629 |
{ |
| 630 |
|
| 631 |
LPSTR subStr = NULL; |
| 632 |
LPSTR returnMsg = NULL; |
| 633 |
for(DWORD i=0; i<strlen(lpMsgBuf); i++) |
| 634 |
{ |
| 635 |
if(lpMsgBuf[i]=='%' && lpMsgBuf[i++]=='%') |
| 636 |
{ |
| 637 |
|
| 638 |
DWORD starIndex = i+1; |
| 639 |
DWORD tmpIndex = i+1; |
| 640 |
while(isDigitNumber(lpMsgBuf[tmpIndex])) |
| 641 |
{ |
| 642 |
tmpIndex++; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
if(tmpIndex > starIndex) |
| 647 |
{ |
| 648 |
LPSTR digitStr = new char[tmpIndex-starIndex+1]; |
| 649 |
for(DWORD j=starIndex;j<tmpIndex;j++) |
| 650 |
{ |
| 651 |
|
| 652 |
digitStr[j-starIndex]=lpMsgBuf[j]; |
| 653 |
|
| 654 |
} |
| 655 |
digitStr[tmpIndex-starIndex] ='\0'; |
| 656 |
|
| 657 |
DWORD msgId = atoi(digitStr); |
| 658 |
|
| 659 |
LPSTR errorMsg = NULL; |
| 660 |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 661 |
NULL, |
| 662 |
msgId, |
| 663 |
0,// Default language |
| 664 |
(LPTSTR) &errorMsg, |
| 665 |
0, |
| 666 |
NULL ); |
| 667 |
if(errorMsg != NULL) |
| 668 |
{ |
| 669 |
DWORD size = strlen(lpMsgBuf)-(tmpIndex-starIndex)+ strlen(errorMsg); |
| 670 |
returnMsg = new char[size+1]; |
| 671 |
strncpy(returnMsg,lpMsgBuf,starIndex-2); |
| 672 |
returnMsg[starIndex-2] = '\0'; |
| 673 |
strcat(returnMsg,errorMsg); |
| 674 |
strcat(returnMsg,lpMsgBuf+tmpIndex); |
| 675 |
return returnMsg; |
| 676 |
} |
| 677 |
|
| 678 |
} |
| 679 |
|
| 680 |
} |
| 681 |
|
| 682 |
} |
| 683 |
if(returnMsg == NULL) |
| 684 |
return lpMsgBuf; |
| 685 |
else |
| 686 |
return returnMsg; |
| 687 |
|
| 688 |
|
| 689 |
} |