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
721 Views

Similar Articles

[PageSpeed] 8

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

recieved error message 0x8DE00006
I cannot get Outlook to send a mass mailer out to business emails. Is ther a max amount that I can send too? I just keep getting this error message and then I go to look it up and there is not solution. Please help!? I have about 375 emails addresses in a distribution list. I just can't seem to send it out. This is most probably an issue with your ISP. They put a quota on how many emails you can send out at a single time. It is a control put in place to restrict Spam. Call your ISP for info -- Peter Please Reply to Newsgroup for the benefit of others Requests fo...

"Application has failed to start..." error message with VS2005 on new machine
VC++ MFC Project working absolutely fine on one machine Installed Visual Studio on a new portable and copied the project and all the settings over, done a complete rebuild which worked fine but now get an error message "The application has failed to start becuase the application configuration is incorrect. Reinstalling the application may fix this problem" Have tried reinsalling (but I dont think this is relevant as I am working with VStudio) the message pops up a couple of times but then the program runs OK Does anyone know what this means and how to find out what is missin...

Cannot show, import, export userform: error &H80004005 / component is not corretly installed
Please, help me! I can not find where is the the information I need. My problem is: I had Windows 2000 and Office 2000. Now they installed Windows XP and Office 2000 (serv.pack 3). And my forms do not work anymore! The error message says nothing useful, only: 1) the component is not corretly installed (ok! but it's a common form with only normal windows common buttons and labels, not a single userparty creative control) 2) error: &H80004005 -2147467259 3) memory insuficient (ahah, at 512 Mb, only Excel running... ) 4) can not set OleObjectBlob property But if I try to open the...

All macros failing part way through with different error messages
All the macros I have in various workbooks are failing - usually part-way through - with different error messages each time. When I check the debugger and try to edit the text, there seems no reason why there should be a problem. The macro has so far stopped on instructions to : - open a workbook - select a worksheet - paste a column in a different place Several times the macro has just stopped running without completing and without showing an error message. I cannot run a host of urgent daily reports without using the macros. Please help! NO way to help unless you tell us exactly...

IE8 Will Not Open in Windows 7
I purchased a new PC shortly before Windows 7 was launched. I was able to purchase a disk from the PC manufacturer allowing me to upgrade when Windows 7 was released. I have an IE icon in the task bar but wheh I click it, the hour glass appears fro a few seconds and vanishes. I have scoured for information including open IE with no add ons, creating a new icon etc but nothing works and it will not open. Any ideas please. Does it open in no add-ons mode? See this link for steps you can take http://support.microsoft.com/kb/936213 -- -- "Brummie" <Brumm...

VLookup in VBA giving error message
Hi, I'm having trouble making the vlookup function work in VBA. the values that are used are all dates, I don't know if that makes a difference. Worksheets("sheet1").range("a1").value = application.WorksheetFunction. _ Vlookup(Range("c1"), range("a:a"), 2) this gives me a run-time error '1004' Unable to get the vlookup property of the Worksheet function class so i tried this: Worksheets("sheet1").range("a1").value = application.Vlookup(Range("c1"), _ range("a:a"), 2) but this gives me a #REF ...

Exchange Connector Wizard error
I received this error while trying to run this wizard for a generic CRM user(what role does it have to have?) that would accept all email directly to CRM. I ran it on a client computer (was this wrong?) Here is the error, anyway. "Failed to initialize the rule management subsystem." What is the correct procedure to run this wizard? I did not find it anywhere. Thanks! ...

is there anyway to access funcion written in c by vc++
hi Is this is possible to access ,a function written in C by VC++. Arbind >Is this is possible to access ,a function written in C by VC++. Yes. I suspect you need to know about using extern "C" to tell the compiler that your function is 'C' rather than C++. For example: extern "C" int MyFn( int p1 ); You often use it like this: extern "C" { #include "Your_C_Header.g" } Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq >#include "Your_C_Header.g" or even #include "Your_C_Header.h" who put that g key in the wa...

Vb.net 2008 ContextMenuStrip logical error when running code
Greetings, I have a connectmenustrip item that when clicked runs the following code (see below) Now if the event is called by the button i.e. cmdDeleteingBooking.Click the linq query returns the appropriate value. However when called by cntMnuCancelBookingItem.Click is returns 0 even if a checkbox is of 'TRUE' value. Debugging shows the code runs exactly the same code (which loops around rows in a datagridview checking if the checkbox has been checked). Could someone explain the reasoning why the same code would return different results? Private Sub cmdDelete...

Metadata Cache Error 04-14-04
When trying to "Go Offline" after synchronization completes I receive the: "Metadata Cache Error" No Entity Anyone experience/solve this issue? Hi, You may have replication setup issue on your SQL server, I suggest you to go through this article : http://mbs.microsoft.com/TechKnowledge/techknowledge.asp?print=true&id=33588&code=7842 If this is OK, you may test the following manipulation : Open SQL Enterprise Manager; go to Start select All Programs and then Microsoft SQL Server. Expand Microsoft SQL Servers, expand SQL Server Group, expand your Microsoft CR...

js error in ie8
Hi, i am opening a popup window in ie8, the popup is load with loaded with one url and some javascript classes are intialized and able to call the member functions are from page and then i am re-directing the page the another url and the js classes are reinitialized. when i try to call the member function of the js class in the re-directed page, ie8 throws js error as "Unexpected call to method or property access". When debug the code, i found that the class is properly initialized and able to access the member variables of the class. i am getting problem only ...

Lexmark driver for Windows Vista??
does anyone know how to get a driver for my Vista program for a Lexmark X75 printrio? Any help appreciated? On Sun, 3 Jun 2007 15:07:39 -0500, "Kitty Stringfellow" <kikkimomjj@sbcglobal.net> wrote: > >does anyone know how to get a driver for my Vista program for a Lexmark X75 >printrio? >Any help appreciated? I'd suggest reposting your question in a newsgroup supporting Vista, or Lexmark. This newsgroup is for questions about designing relational database Queries in Microsoft Access. John W. Vinson [MVP] ...

Label Error with image?
Hi, We are trying to print a label for jewelry, the only issue we seem to have is that when an image is put into the label designer the image is the right dimensions but instead of being an image it is a box with red lines cris-crossing with the word 'ERROR' displayed in the center. This all happens before printing, although when we try to print there is no image. So what is it that we are doing wrong to not have an image displayed in the Label designer of RMS PO Manager. Any help[ would be greatly appreciated! Thanks ___________________ Dave Dave, In Label Designer, you have ...

Frx Susbcript 9 error
I am running a consolidated Income Statement in FRx and I get an Error 9 when it hits this one company. It consolidates 5 different companies, one that is translated. I just can;t figure it out. I have a very similar Balance Sheet that runs just fine. I have tried everything, change the output names, etc. I can run the report if I just select that one company but when I run the total company it won't run, it stops with the error. I am using row linking and currency translation. I can run the report for all companies individually. I just don't get it. I have gone through the various kb...

error on install to pocket pc
"window\mny2day.dll" is in use or is in ROM. IFthe file is not in ROM, please close the application using the file. I do not understand what file could be using the same application or how to check the ROM. ...

invoice for envelopes with windows
What invoice template can I use that will consistently place the name and mailing address on the invoice form so that it will always fit in the window of an standard #10 business envelope? There is no standard location for the window. I would suggest folding a piece of paper and measuring where the window is on the envelopes you use. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Mary" <Mary@discussions.microsoft.com> wrote in message news:68FC09EF-AA33-40D7-8472-1602F50D69BD@microsoft.com... > What invoi...

Sql Agent Error
After installing CRM we are receiving the following error. "An error occurred when attempting to set the SQLSERVERAGENT service to AutoStart: System.ComponentModel.Win32Exception: The specified service does not exist as an installed service at Microsoft.Crm.Setup.Common.Utility.ServiceUtility.SetServiceToAutoStart(String serviceName, String machineName) at Microsoft.Crm.Setup.Server.ServiceRunningValidator.AutoStartLocalService(String serviceName, TimeSpan waitTimeForStart) We have CRM on a SBS 2003 machine and SQL EE 2000 on a W2K3 machine. Both are DCs the SBS holds all FS...

Interesting Solver problem (Solver encounters an error)
Here's an interesting problem, I wonder if anyone has any thoughts o this. Recognize that my real problem is very complex (severa intermediate calculation including some iterative steps), but th problem I'm having seems similar (conceptually anyway) to this simpl problem. Given a data set: x,y 10,3.9 8,3.2 7,2.8 6,2.2 5,1.4 4.5,0.8 4,0.01 3.8,-0.4 3.6,-1 3.5,-1.4 3.4,-1.8 3.3,-2.4 3.2,-3.2 3.1,-4.6 3.05,-6 One could look at the data and say, "that looks like the curve y=ln(x) but with a different asymptote other than the y-axis and possibly scaling factor." So we choos...

IM error ADO field is nothing
I am trying to do an import for manual payroll checks. I have used the same set up as is used in the sample but I recieve the above error. It also says 0 integrations failed. I can't find anything in knowledgebase. Thanks for any help. Tracey D Open IM, select your integration, double-click on Mappings. Click on the Transactions collection, then click on the Options tab. You will want to make sure the Record Source option rule is set to Use Source Recordset and that the Source is set to your source query. If the above is defined properly, then you will want to make sure you a...

Only new email window?
Is there a way that I could have a shortcut on my desktop that does not open the whole application, but rather ONLY open my new email window? I send out a lot of email, and I also have a lot of other apps running. Please let me know if that is possible. Thank you, Steve Steve F. <sf@flintind.com> wrote: > Is there a way that I could have a shortcut on my desktop that does > not open the whole application, but rather ONLY open my new email > window? I send out a lot of email, and I also have a lot of other > apps running. Create a shortcut whose target is: "%Pr...

trial & error
How do I calculate the z factor automatically by trial & error EggHeadCafe - .NET Developer Portal of Choice http://www.eggheadcafe.com You keep asking about the z factor. What's the z factor? - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ <khalid khalid> wrote in message news:200782610734gawarh@hotmail.com... > How do I calculate the z factor automatically by trial & error > > EggHeadCafe - .NET Developer Portal of Choice > http://www.eggheadcafe.com ...

Exchange Server C Drive No free space
Hi All, Need some advise. The Exchange Server during certain times C Drive will not have free space. I have check that during that period there is a temp file which will increase in size and takes up all the disk space in C. The file will not have any extension (the file name ex. T232C or R408). When this happened, the Exchange MTA service will stop, users will not able to send email. I have rum Spyware scan, Virus Scan, Online Virus scan, all seems to be cleaned). Anyone experience this before? Thanks in Advance for the help. -- Danny Chieng Technical Engineer On Wed, 26 Jul 2006...

Outlook reports OLE registration error
I have Office 2000 running in Windows Me on a Dell Dimension XPS D266 with 64 meg ram. Outlook stopped working so I ran Repair from Office 2000 CD and then Re- install Office from same source. Both times Outlook says" An OLE registration error occured. Program is not correctly installed. Run Setup again." Doesn't seem to be much sense in running it again. What now? Reinstall Outlook Express. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal acco...

parent window?
hi, Im trying to display bmp image using static control.I have created a pointer as cstatic stc; when i use stc.Create(NULL,SS_BITMAP,pos,?); what shall i give for the parent window of static control? i used getactivewindow(),but i was not able to display bmp when setbitmap(Hbmp) is used. thanks in advance susi ...

Cdn Payroll July 1 errors
Since the tax update was installed for July 1 for Canadian Payroll, our Detail Range Reports do not have the proper data. I noticed that CPY30260 has not been updated!!! this is not good. I contacted our vendor to see if this is a known issue. There is a round2 tax update that does not affect our province so I have not installed it. I was waiting for round3 which has not been released yet. Is anyone else aware of this? We have not seen any errors during Update Masters. Our YTD amounts and T4 amounts appear to be correct. thanks. never mind "barbola" wrote: > Since the...