|
I am using thread, when I debug, It is crashing after completion of thread
---------------------------
navigator.exe - Application Error
---------------------------
The instruction at "0x5f43690b" referenced memory at "0x02470014". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
---------------------------
OK Cancel
---------------------------
|
|
|
|
|
How do you expect any help with the details you've given? Provide more information such as:
- Source around the crash.
- Values of the variables of interest.
- Stack trace to crash.
- Machine code around crash and register values.
- ...Basically anything...
Steve
|
|
|
|
|
This is access to already delete memory block. One common case is deleting a memory block or object two times or dealing with a in another thread.
Tip: check if the address is constant or changing and look what is in it.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: This is access to already delete memory block
That is only ***ONE*** possible cause.
Steve
|
|
|
|
|
Dear All,
My project requirement is VC++ application need to display the color of individual cells using CListCtrl.How to implement this.
It will be much helpful to me to give some advice on this..
Thank you very much,
Yours,
Anitha
|
|
|
|
|
|
|
thUpdateUI= AfxBeginThread (StartUpdateUIThread, _param);
WaitForSingleObject(thUpdateUi,INFINITE);
but dosn't wait for the thread to complete
modified on Tuesday, August 19, 2008 2:37 AM
|
|
|
|
|
IF you just want to block the current thread till the other thread completes why use threads??
You can just call the function
UINT iRet = StartUpdateUIThread(_param);
I hope it helps..
I think you did not like my opinion
Regards,
Sandip.
modified on Tuesday, August 19, 2008 2:53 AM
|
|
|
|
|
The call bock the whole main thread, so
|
|
|
|
|
ptr_Electron wrote: The call bock the whole main thread, so
Quote Selected Text
What does it mean? Even WaitForSingleObject will block the current executing thread(Main Thread).
BTW MSDN Says
The WaitForSingleObject function checks the current state of the specified object. If the object's state is nonsignaled, the calling thread enters the wait state until the object is signaled or the time-out interval elapses.
I think you did not like my opinion
Regards,
Sandip.
modified on Tuesday, August 19, 2008 2:54 AM
|
|
|
|
|
Try something like this:
CWinThread *pThread = AfxBeginThread(&StartUpdateUIThread, _param, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
ASSERT(pThread);
HANDLE hThread;
VERIFY(DuplicateHandle(GetCurrentProcess(), *pThread, GetCurrentProcess(), &hThread, 0, FALSE, DUPLICATE_SAME_ACCESS));
pThread->ResumeThread();
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
It's probably a good idea to wrap all this mess in a helper function.
Steve
|
|
|
|
|
::AfxBeginThread() does not return a handle that can be used for waiting. It returns a pointer to a CWinThread object.
ptr_Electron wrote: but dosn't wait for the thread to complete
If you would have bothered to check the return value from ::WaitForSingleObject() you would have found that the operation failed. A call to ::GetLastError() would most likely return ERROR_INVALID_HANDLE . To omit the validation of the return value is just sloppy.
A few days ago you had almost the same question regarding the same problem, which I replied to here[^].
I suggested an article that would explain all this and teach you how to do it the right way. If you would have bothered to read the article, this question would not have been necessary. I can see that you now use ::AfxBeginThread() instead of ::_beginthreadex() , but that's not enough.
Read the article here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
ptr_Electron wrote: I started the thread and want to wait until the thread completes
Why?
Do you think you're getting some benefit from having a second thread
used that way?
That sure is a complicated way to do single threaded programming.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi All,
I wanted to use NET API in my MFC application, since this was new to me I started out with a simple application listed below
#include "stdafx.h"
#include "myapp.h"
#using <mscorlib.dll>
#using <system.dll>
using namespace System;
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
Console::WriteLine("This is a MFC app using NET API");
}
return nRetCode;
}
Till few days back I was able to successfully compile and run this simple application using VC++ 2005 with SP1, however now when I am trying to compile the application I am getting the following error
1>.\myapp.cpp(45) : error C3666: 'System::Security::IEvidenceFactory::IEvidenceFactory' : override specifier 'new' not allowed on a constructor
1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : error C3611: 'System::Security::IEvidenceFactory::GetLifetimeService': a sealed function cannot have a pure-specifier
1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>.\myapp.cpp(45) : error C4687: 'System::Console': a sealed abstract class cannot implement an interface 'System::Security::IEvidenceFactory'
1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>.\myapp.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The MSDN documentation is not very helpful on the error message and also the fact that I am new to NET arena so I really do not understand what went wrong.
In the last few days I have installed DotNET framework 2.0 SP1 on my machine and many other applications required by my project so it is difficult for me to go back to pre 2.0 SP1 configuration.
Does someone no what is this error? And how do I get rid of this.
Thanks and Regards
|
|
|
|
|
You cannot use the .NET framework from a native application (MFC, C, C++, whatever).
If you want to use applications that exploit the features of .NET framework, then you will need to write code in one of those managed languages (C#, VB.NET, CLI/C++)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
You can make a dll and use of it on the c++ or vice versa.
|
|
|
|
|
Hi!
I've to run an exe from another Project. This exe is in the same machine only. Shall I use Remote Procedure Call to achieve this? How to do Remote Procedure Call in C++?
|
|
|
|
|
|
I don't know the which values should I pass to the parameters. Can u please expalin?
|
|
|
|
|
|
T.RATHA KRISHNAN wrote: I don't know the which values should I pass to the parameters
what do you think the docs[^] are for ???
|
|
|
|
|
Use CreateProcess if you want more control over process being spawned
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
T.RATHA KRISHNAN wrote: Shall I use Remote Procedure Call to achieve this?
What does RPC or MIDL has to do here? You want to learn RPC or just run an executable?
If you need to run an executable, you just need ShellExecute or CreateProcess as someone already said.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
T.RATHA KRISHNAN wrote: I've to run an exe from another Project.
See here.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|