Not Work in worker thread in MFC application with visual studio 2010

57 views
Skip to first unread message

liang leon

unread,
Oct 29, 2011, 9:40:18 PM10/29/11
to Crashrpt
I just use the following to test in a MFC application ,
CrashRpt work well when crash in main thread, but not work in worker
thread. It seem no CrashRpt hanlder get called at all .

DWORD WINAPI ThreadProc(LPVOID lpParam)
{
// Install exception handlers for this thread
crInstallToCurrentThread2(0);


for(;;)
{
// There is a hidden error somewhere inside of the loop...
int* p = NULL;
*p = 13; // This results in Access Violation
}

crUninstallFromCurrentThread();

return 0;
}

zexspectrum

unread,
Oct 30, 2011, 12:06:02 AM10/30/11
to cras...@googlegroups.com
Hello, I tried to reproduce your issue and created a simple MFC app. It seems to work. I've attached the MFC application MfcTest to this message. 

Steps how I ran the app:
1. Downloaded CrashRpt v1.3.0, and compiled it with Visual Studio 2010.
2. Opened MfcTest.sln in Visual Studio 2010.
3. Right-clicked the MfcTest project, selected Properties from context menu. 
4. In the Properties dialog's VC++ Directories list, added path to CrashRpt's include and lib directories.
5. Compiled MfcTest solution (pressed F7).
6. Copied CrashRpt1300.dll, crashrpt_lang.ini, dbghelp.dll from CrashRpt's bin directory to MfcTest's debug directory.
7. In the MfcTest's debug directory, clicked on MfcTest.exe to run it.
8. CrashRpt window appears as expected.

What is the difference between these steps and the steps you do?
MfcTest.7z

liang leon

unread,
Oct 30, 2011, 2:04:51 AM10/30/11
to Crashrpt
Hi, thank you for reply,
I test you app, it does work well.
But I dont't know why my project just dont't work.
My step is no different with yours.
Can you test my project?But i can't attach file here.
I think maybe project setting problem.But I just use the default form
vs2010.

liang leon

unread,
Oct 30, 2011, 2:51:53 AM10/30/11
to Crashrpt
I found some hints.
For doc/view application , or for simple GUI win32 application
(without mfc),
you must put the install rt code after main windows created. or ,you
will not get ReportRpt work in worker thread.

these code not work

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{

UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

CR_INSTALL_INFO ii;
memset(&ii, 0, sizeof(CR_INSTALL_INFO));
ii.cb = sizeof(CR_INSTALL_INFO);
ii.dwFlags = CR_INST_ALL_POSSIBLE_HANDLERS;
ii.pszAppName = _T("MfcTest");
ii.pszAppVersion = _T("1.0.0");

int nResult = crInstall(&ii);
TCHAR szError[256];
crGetLastErrorMsg(szError, 256);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CRASHWIN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}



hAccelTable = LoadAccelerators(hInstance,
MAKEINTRESOURCE(IDC_CRASHWIN));

// Create the worker thread
HANDLE hWorkingThread = ::CreateThread(NULL, 0,
ThreadProc, (LPVOID)NULL, 0, NULL);
// Main message loop:
//int* p = NULL;
//*p = 13; // This results in Access Violation
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
crUninstall();
return (int) msg.wParam;
}



that code will work

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{

UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);


// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CRASHWIN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

CR_INSTALL_INFO ii;
memset(&ii, 0, sizeof(CR_INSTALL_INFO));
ii.cb = sizeof(CR_INSTALL_INFO);
ii.dwFlags = CR_INST_ALL_POSSIBLE_HANDLERS;
ii.pszAppName = _T("MfcTest");
ii.pszAppVersion = _T("1.0.0");

int nResult = crInstall(&ii);
TCHAR szError[256];
crGetLastErrorMsg(szError, 256);

hAccelTable = LoadAccelerators(hInstance,
MAKEINTRESOURCE(IDC_CRASHWIN));

// Create the worker thread
HANDLE hWorkingThread = ::CreateThread(NULL, 0,
ThreadProc, (LPVOID)NULL, 0, NULL);
// Main message loop:
//int* p = NULL;
//*p = 13; // This results in Access Violation
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
crUninstall();
return (int) msg.wParam;
}

zexspectrum

unread,
Nov 6, 2011, 8:01:18 AM11/6/11
to cras...@googlegroups.com
Hi, 

I tried to reproduce your problem with GUI win32 application. I created my own Win32 app from scratch and it worked well with CrashRpt. 

I used the first case, when crInstall is called before window creation. 

I attach the application to this message. Does it work for you?
winapi_test.7z
Reply all
Reply to author
Forward
0 new messages