Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The program I maintain in work auto terminate without any error information, I can confrim that the problem is in one of DLLs loaded, but there are tens of dll in problem, which one crash is hard to find.
I create a test program in VC6 to emulates the situation. The error codes list below:
C#
char pTest[2] = {0};
    strcpy(pTest, "hello world!ccccccccccccccccccccccccc");


if the code in a console program like fllowing codes, the error can be detected by CrashRpt.
#include "stdafx.h"
#include <windows.h>

typedef BOOL ( CALLBACK *ENUMSIGNALPROC )( int, float, LPVOID );
typedef BOOL (*PQUERY)(HANDLE, int, ENUMSIGNALPROC, LPVOID);

#include "./crashrpt/include/crashrpt.h"
#pragma comment(lib, "./crashrpt/lib/crashrpt")

int main(int argc, char* argv[])
{
	LPVOID m_lpvState;
	m_lpvState = CrashHandle_Install(NULL,NULL, NULL);
        CrashHandle_SetIsInteractive(m_lpvState,false);
        CrashHandle_SetIsKillProcess(m_lpvState,false);

        printf("Hello World!\n");

	char pTest[2] = {0};
	strcpy(pTest, "hello world!ccccccccccccccccccccccccc");

	printf("222222222222222222222222\n");
	return 0;
}


but if the error codes in dll, the error will not be catch by CrashRpt. codes below:
int main(int argc, char* argv[])
{
	LPVOID m_lpvState;
	m_lpvState = CrashHandle_Install(NULL,NULL, NULL);
   CrashHandle_SetIsInteractive(m_lpvState,false);
   CrashHandle_SetIsKillProcess(m_lpvState,false);

	printf("Hello World!\n");
	
	HMODULE hMod = LoadLibrary("COM1_cu06h.DLL");
	if (hMod != NULL)
	{
		PQUERY p =	(PQUERY)GetProcAddress(hMod, "Query");
		if (p != NULL)
		{
			for(int i=0; i<30; i++)
			{
				p(0, 0, NULL, 0);
				printf("--------\n");
			}
		}
	}
	printf("222222222222222222222222\n");
	return 0;
}

the DLL code lists below:
int g_nSampleCnt = 0;
DLLExport BOOL Query(HANDLE hCom, int nNo, ENUMSIGNALPROC proc, LPVOID lp)
{
    char pTest[2] = {0};
    try
    { 
	g_nSampleCnt++;

	if(g_nSampleCnt == 3)
	{	
	   strcpy(pTest, "hello world!ccccccccccccccccccccccccc");
	}
    }
    catch( ... )
    {
        OutputError( ErrLog_FILE, "\r\n .DLL Error\r\n" );
    }
    
    g_nSampleCnt = g_nSampleCnt%30;
		
    return TRUE;
}


I used the try...catch(...) and __try...__except and SEH method, its can catches the exceptions like devision by zero, but the codes like this will not be catched.
char pTest[2] = {0};
strcpy(pTest, "hello world!ccccccccccccccccccccccccc");


Any solutions or tools recommended will be appreciate.
Posted
Updated 11-Oct-12 17:46pm
v4
Comments
Sergey Alexandrovich Kryukov 11-Oct-12 22:29pm    
What is "auto exist"? :-)
--SA
Sergey Alexandrovich Kryukov 11-Oct-12 22:34pm    
What do you mean "only (!) catches the errors..."?! If it catches, it catches exceptions, not "errors", and, if this is, for example, integer division by zero, an uncaught exception will get your application terminated. Find these situations and -- case closed.
--SA
王鹏飞 11-Oct-12 23:32pm    
It's spelling fault, i want to use 'exit', it's your means 'terminated', my question is that the try...catch can catch the exceptions like division by zero, but the codes i list above will not be catched, so the program will terminate. In my software, there are tens of DLLs loaded, it's hard to located which one have problem. so i want to find a method can trace which dll throw exception
Sergey Alexandrovich Kryukov 11-Oct-12 23:54pm    
Have you been able to use the debug window "Call stack" after the exception is thrown and caught? It would show you all you need. Did you catch all exceptions on the top stack frame of the stack of each thread? Do all of your DLLs have debug information?
--SA
王鹏飞 12-Oct-12 0:10am    
The terminated sitution can not be recurred in our develop environment, program terminate in client environment nonperiodic. I used try...catch for all dll calling thread, but its can't be catched. our problem have log message, but clients not permit to replace all dlls with have logged verion, and it's multithread problem, the log will hard to analize.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900