debug assertion error in threads of c++ under windows

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.

0
3/12/2007 12:22:56 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
533 Views

Similar Articles

[PageSpeed] 32

"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.
> 

Probably the string where the strFileName reference parameter was referring 
to went out of scope while (or before) your thread was running. 

If that happened, sstrFileName in this line points to invalid memory:
me->OnSaveDocument ((LPCTSTR)sp.sstrFileName);

Making sstrFileName a string or CString in stead of LPCTSTR will fix this.

Also you're mixing string with LPCTSTR which won't work if you compile for 
UNICODE.

Wim
0
Wim (6)
3/12/2007 12:43:26 PM
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]

0
Scott
3/12/2007 1:57:01 PM
Reply:

Similar Artilces:

Vlookup N/A# error and VALUE# error
I have a list of part numbers that contain text and numbers, I am trying to pull data from another worksheet over by using the part number as my common entity. However I keep getting either a N/A# error or a #VALUE error. The two functions that I am using are: =VLOOKUP(--F3&"",Table!$B$3:$D$957,2,FALSE) and =VLOOKUP(--F3,Table!$B$3:$D$957,3,FALSE). I am using the first function to pull data from the second column on the table worksheet into the G3 cell. I am using the second function to pull data from the third column on the table worksheet into the H3 cell. Please h...

Hotmail Spelling Error
Even Microsoft can make spelling errors as seen in this message when exiting Hotmail and not having 3rd party cookies enabled. Read the last line... ....and why do we need 3rd party cookies enabled anyway? Sign out failed! We could not sign you out because your browser seems to be blocking third party cookies. a.. Close all browser windows to sign out. b.. To prevent this error in the future, you must enable third party cookies by chaging your browser settings. On Wed, 16 Dec 2009 14:44:54 -0500, John wrote: > Even Microsoft can make spelling errors as seen in this...

Autosize Error
Column is set to wrapping text the row height is automatically sized, I find quite regular rows sized for twon lines of text but text is only one full line?! What it the problem here? w ...

Disposal of Greetings 2002 for Windows XP
Is there anyone now using Publisher who might have a no longer used Greetings 2002 they would like to dispose of? It must not have a OEM product ID No. or I shall not be able to transfer it to my Windows XP computer. Many thanks. Sybil Fox I have it but it is an OEM version. Try eBay. -- JoAnn Paules MVP Microsoft [Publisher] "Sybil Fox" <shfox@worldonline.co.uk> wrote in message news:ueI2hCkpFHA.708@TK2MSFTNGP09.phx.gbl... > Is there anyone now using Publisher who might have a no longer used > Greetings 2002 they would like to dispose of? It must not hav...

Dialog and asserts
Hi, I have a dialog based application and I want to open another dialog. I have a function int CMyDialog::Execute { // CMyDialog::Execute int ret_code; CNewDialog m_NewDialog(this); ret_code = m_NewDialog.DoModal(); return ret_code; } // CMyDialog::Execute that opens this dialog but this fail :( I got at assert on this line BOOL CWnd::Attach(HWND hWndNew) { ---> ASSERT(m_hWnd == NULL); // only attach once, detach on I have realized my application with the Wizard so I am not very expert about this stuff. Can someone tell me what's happening ? Stefano Malavasi __...

Error registering GetFavorateSummary trigger after installing Dynamics GP Service Pack
After installing the Service Pack for Dynamics GP the following Dexterity Runtime error is displayed when logging in to GP: "An unexpected error was encountered trying to register the trigger: GetFavoriteSummary. Error 2. This trigger will be disabled." You can click OK, login, and everything appers to be fine. This happens on all clients including the client installed on the SQL Server. Does anyone know how to resolve this? Well, one of the 3rd party products you have loaded is triggering on something and it's failing, likely because the parameters have changed in the ser...

Error Message #40
Switched email from pop3 ISP to Exchange Server 2003. Some of the email prior to the switch can not be opened. I recieve this error message: "can't open this item. could not complete the operation because the service provider does not support it." Please help! Any suggestions would be appreciated. Thanks. ...

checks error
Hi, we have a problem when trying to print payable checks, it says duplicate check numbers exist for checks in this batch.. what is that means and how to solve it? thanks Mary, This may or may not be an error depending on your checkbook and Payables Management settings. You can mark whether to allow duplicate document numbers per vendor, using the Payables Management Setup window (Microsoft Dynamics GP > Tools > Setup > Purchasing > Payables). Also, in the Checkbook Maintenance window (Cards - Financial - Checkbook), there is an option to allow duplicate check numbers i...

Error on 'Insert Template'-email if Regarding field has a < charac
Hi, In CRM 4.0 in my Email Activity when I click on 'Insert Template', it shows unhandled exception whenever the regarding field value of Email contains a '<' (less than) charater. However it works correctly when this character is removed from Regarding field. Has anyone faced this problem ? ...

w3svc1372222313 IIS Logs
I manage a number of SBS 2008 installations, and each one of them has this problem - C:\inetpub\logs\LogFiles\W3SVC1372222313 is filled with daily logs, most of them 1.5GB in size - in one case there were over 100GB of these files. I deleted all but the last 7 days in each case, but I wonder if this is a bug of some kind - what could this IIS instance be doing to create logs of this size? Hi Albee: Have a look at this: http://blogs.technet.com/sbs/archive/2008/02/28/reclaiming-disk-space-lost-to-iis-logs-on-sbs-2003.aspx - Larry Please post the resolution to your...

DEBUG
Curious, new problem has started. Evey once in a whle a new folder appears on my desktop labeled "debug"..The folder is empty and I do not know how it is formed or why..Does someone know the cause of this and a remedy so it does not appear again Thanks Running Xp professtional heshie wrote: > Curious, new problem has started. Evey once in a whle a new folder appears on > my desktop labeled "debug"..The folder is empty and I do not know how it is > formed or why..Does someone know the cause of this and a remedy so it does > not appear again &g...

Application log errors
Suddenly, I'm seeing Event ID 2003 Source Perflib event messages for the "w3svc", "msftpsvc", "ASP", and "InetInfo" services. Why are these message appearing? I don't seem to recall any changes being made on the Exchange 2000 server (on Windows 2000 Server). Also, I'm seeing Event ID 1000 Source FTPCtrs. Is this because the FTP Publishing Service is disabled? thanks. I think this is what you are talking about. http://support.microsoft.com/kb/267831 "wli2k2" <wli2k2@discussions.microsoft.com> wrote in message n...

NetBT error
Hi, I have the same error message in event viewer coming up between every 5-20 mins. Event Type: Error Event Source: NetBT Event Category: None Event ID: 4319 Date: 2/21/2007 Time: 12:30:39 AM User: N/A Computer: SFBRIEX2 Description: A duplicate name has been detected on the TCP network. The IP address of the machine that sent the message is in the data. Use nbtstat -n in a command window to see which name is in the Conflict state. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp. Data: 0000: 00 00 00 00 01 00 58 00 ......X. 0008: 00 00 0...

outlook 2007 error message in archive folders
for no discernable reason some and only some of my archive folders will no longer open and give the following error message: the message interface has returned an unknown error. If the problem persists restart Oultlook I have restarted not only outlook but rebooted my computer with no positive result. I have also gone back a month to a restore point but this has not changed the position. As I say it is only some files and then only some subfiles in larger files. One month ago there were no issues. I have added no new programs to the computer Try running scanpst.exe against y...

Debug Assertion Faild
Debug Assertion Fail Program: C:..... File: winocc.cp Line: 22 The exception Breakpoin A breakpoint has been reache (0x80000003) occurred in the application at location 0x5f4369c This program is to scan a file and look for a matching string. Could this error be caused by code not exiting a "break;" properly? I'm not sure how to explore resolving this. The information listed in the Debug is The thread 0x3DD8 has exited with code 0 (0x0) The thread 0x3EA8 has exited with code -2147483645 (0x80000003) The program 'C:\Documents and Settings\Owner\My Documents\Dads\Programmi...

Demote DC and DCOM error
I am getting an error message in my event viewer after demoting a DC. The error states "DCOM was unable to communicate with the computer <DC_Name> using any of the configured protocols. Also, I removed that DC in the Active Directory Sites and Services after demoting it. Thank you in advance for the help. "Jonathan Zaldivar" <jczaldivar1@verizon.net> wrote in message news:e%23U1RbvaKHA.5472@TK2MSFTNGP02.phx.gbl... >I am getting an error message in my event viewer after demoting a DC. The >error states "DCOM was unable to communicate w...

An application crashes only under debugging
Hi, I'm using VC++ 6.0. I have a Win32 Application (I will call it "EXE") which is linked with a Win32 DLL and I don't have the source files of the DLL; When I execute the EXE by double-clicking on the icon reprsenting it , there are no problems; On the contrary, if I try to debug the EXE the program crashes: in fact, the debugger shows an "Access Violation" error message and informs that an istruction of the DLL attempts to read a memory location which cannot be read. Does someone know a possible cause of this problem? Thanks. M If the DLL is an MFC DLL (it is...

GPS Error 56 Followed By SQL Error 208 and "Invalid Object Name"
I am getting this letter in SmartList Builder - I am trying to add a table from a different (Non Great Plains) database so that I can put these fields in a smartlist. Any ideas/suggestions appreciated. Thanks ...

Error 70
I have a small sub that has been in a program for many years. I use the program only once a year in March. The routine is suppose to intercept an ENTER key and create a Tab key input. The routine is: If KeyAscii = vbKeyReturn Then KeyAscii = 0 ' suppress the beep SendKeys "{tab}" End If When the program attempts to execute the sendkeys statement I get the error indicated. I have attempted to run the program as Administrator with the same results. Previously the program ran under XP and VISTA. I now run it under Windows 7. Coul...

401 error when viewing reports
Hello, I'm having a final problem getting the reports to work in CRM. When I try to view reports I get the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- The request failed with HTTP status 401: Unauthorized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthori...

Weird: CRichEditCtrl scrollbars work in debug build but not in release build
Hi, I have an App Wizard project (VS 6.0), non doc-view architecture. My view class is: class CRichTextView : public CRichEditCtrl. In MainFrm.cpp I have a member variable of: CRichTextView m_wndView;. I create the view as follows: if (!m_wndView.Create(WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | WS_VSCROLL, CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST)) { TRACE0("Failed to create view window\n"); return -1; } It works "just peachy" in the debug build. But, when I make...

quicken convert errors
When I convert my Quicken 2004 .QDF file to Money 2004, I get multiple errors in the .MNY file. All my dates are 1900 and all my transactions/balances are 0. I've validated my quicken data. Anyone have similiar problems? Thanks M04 cannot import Q04. Only Q03 and earlier. To import Q04 you must go to M05. For many reasons, some of which are listed at http://umpmfaq.info/Money2005.htm, I do not recommend M05. "Jim and Lisa" <j-l-brown@comcast.net> wrote in message news:WamdnQZUX9dMdQLcRVn-sA@comcast.com... > When I convert my Quicken 2004 .QDF file to Money 200...

Windows XP will not open up to the meadow picture
I turn on my computer and it shows the Windows XP symbol. Then it goes into the screen that asks to either Safe Mode Last known good configuration starting windows in XX seconds. Then the seconds go to zero and the loop starts again. It has gone on for 20 minutes on its own. What do I do? I tried the solutions that Microsoft suggested and they did not work. Example go to safe mode and last known... Do I understand that it will not go to Safe Mode or will it just not got to last known good configuration? "Pistol pete" <Pistol pete@discussions.microsof...

Debug in Release mode?
Old wine in old bottle.. being served by a new bartender :o) How do I do this? pointer would be much appreciated. >Old wine in old bottle.. being served by a new bartender :o) > >How do I do this? The subject or the content? To debug a release build see "How to: Debug a Release Build" in your VC++ help. Dave In addition to what Dave suggested you might want to just do a find on this newsgroup using those keywords. There have been several discussions on that topic in the last few days that should pop up a bunch of links. If you can't find them let me know and ...

Delayed Message Error
A user tries to send a message to an aol account and gets the following error message returned: Reporting-MTA: dns;venus.allianceppc.com From: Administrator Sent: Tuesday, June 14, 2005 4:13 AM To: Ron Doe Subject: Delivery Status Notification (Delay) This is an automatically generated Delivery Status Notification. THIS IS A WARNING MESSAGE ONLY. YOU DO NOT NEED TO RESEND YOUR MESSAGE. Delivery to the following recipients has been delayed. rdoe1@aol.com It also includes an attachment with the following error: Reporting-MTA: dns;mailstuff.fakedomain.com Final-Recipient: rfc822;rd...