Re: debug assertion error in threads of c++ under windows

Tech-Archive recommends: Fix windows errors by optimizing your registry



Pushpa wrote:
Hi All,

This my part of the c++ program using threads in windows :

//modified by pushpa
struct structExrdDoc
{
CExrdDoc* spDoc;
LPCTSTR sstrFileName;

structExrdDoc():spDoc(NULL),sstrFileName(""){}
};
structExrdDoc sp;

volatile bool running;

UINT CExcelExport::run(LPVOID p)
{
CExrdDoc* me = sp.spDoc;
me->OnSaveDocument ((LPCTSTR)sp.sstrFileName);
running = FALSE;
return 0;
}
//modified by pushpa

void CExcelExport::SaveExcelFile (CExrdDoc* pDoc, const string&
strFileName)
{
sp.spDoc = pDoc; //modified by pushpa
sp.sstrFileName = strFileName.c_str(); //modified by pushpa
running = TRUE; //modified by pushpa
AfxBeginThread(run,NULL); //modified by pushpa
//pDoc->OnSaveDocument (strFileName.c_str()); //modified by pushpa
}


Here the line of code I have commented was taking lot of time, so I hv
tried to use threads and I am new to this.

This is the declaration in the .h file

static UINT CExcelExport::run(LPVOID p);

After some struggle I could compile the application, but when it is
run I am getting a Debug assertion error.

debug assertion failed!
program:d:\amsa\amsa\bin\gageanalysisdlld.exe
file:wincore.cpp
line:888
for information on how your program can cause an assertion failure,
see the visual c++ documentation on asserts.

Could you please help me with this.

Thanking you in advance,
Pushpa.


In addition to the bug described by Wim...

OnSaveDocument is not designed to be executed from a secondary thread. The problem is related to accessing windows created in the main thread, which is not permitted by MFC. If you look in the stack window when the assert happens you will see where in the CDocument code a window is accessed.

You could write a new document function to save your data without accessing any windows, or you could save the data in the thread function without calling the CDocument function.

--
Scott McPhillips [VC++ MVP]

.



Relevant Pages

  • Re: Changing the Font size of a Static Text control problem
    ... I am trying to set the font size for my static text and I am getting ... this error: Debug Assertion Failed! ... You cannot access windows in an MFC window class ... Move your SetFont call to OnInitDialog, after it calls the base class ...
    (microsoft.public.vc.mfc)
  • How will it new/allocate memory on windows2003 when a class have string-type members?
    ... I declare a class pointer like this: ... windows XP, but It faild on my windows 2003. ... I debug it, and It's assert when the object pointer ccc is released. ... For information on how your program can cause an assertion ...
    (microsoft.public.vc.language)
  • Re: Dell INSPIRON 15 $499 beats an iMac
    ... And corporate America uses Windows because it runs better on big ... LOL your claim is "Microsoft hasn't given their customers ... That's such a ridiculous assertion, ... I cant waste anymore time on this subject with you, its useless. ...
    (comp.sys.mac.advocacy)
  • Re: Assertion in KeUpdateRunTime with Free Build of Windows Vista.
    ... First this is a bugcheck not an assertion. ... Second, fix your kernel symbols ... without this there is no hope of debugging it. ... Windows 2k/XP/2k3 Filesystem and Driver Consulting ...
    (microsoft.public.development.device.drivers)