|
Crashes it in this function or later?
If you did not call CWinApp::OnFileOpen() , no document is created. So the reason for the crash is probably somewhere in your document creation. Did you call OnFileNew() or use ProcessShellCommands() to create a document?
|
|
|
|
|
No, I didn't call CWinApp::OnFileOpen , but I call OpenDocumentFile(...) , something like that:
void CMyApp::OnFileOpen(void)
{
CFileDialog dlg(TRUE);
if(IDOK == dlg.DoModal())
{
POSITION pos = dlg.GetStartPosition();
while(pos)OpenDocumentFile(dlg.GetNextPathName(pos));
}
AfxMessageBox("By here, everything it's OK.");
}
after all, I think that the problem it's in another place ... I really don't know ...
And this is weird, because if I open the same file from MRU, everything is OK ...
modified 5-Apr-13 5:54am.
|
|
|
|
|
It's difficult to find such errors in release versions. Using a message box is a good idea to check where the violation occurs. Because it occurs when not calling OpenDocumentFile() , I assumed that it is somewhere in the document handling (e.g. trying to access non-existing documents).
But when it is OK using ProcessShellCommands() (MRU)
At the moment I have only two ideas:
- Call
OpenDocumentFile() with a fixed file name to see what happens (no other calls from within OnFileOpen() ). - Perform a complete rebuild if you have changed something in your project.
|
|
|
|
|
This is became strange: if I call only:
OpenDocumentFile(_T("D:\\Flaviu\\SampleImages5\\Test.xxx"));
, everything is OK, but when I go through normal way:
CString strFile;
if (dlgFile.DoModal()==IDOK)
{
pos=dlgFile.GetStartPosition();
while (pos!=NULL)
{
strFile=dlgFile.GetNextPathName(pos);
AfxMessageBox(strFile);
OpenDocumentFile(strFile);
}
}
is crashing down ... in Release mode only ...
I have to digg in ...
|
|
|
|
|
So the problematic code is at least isolated even when it looks OK. As next step you may assign the fixed file name to strFile ignoring the selection from the dialog.
|
|
|
|
|
Another trial:
CString strFile;
if (dlgFile.DoModal()==IDOK)
{
pos=dlgFile.GetStartPosition();
while (pos!=NULL)
{
strFile=dlgFile.GetNextPathName(pos);
AfxMessageBox(strFile);
OpenDocumentFile(strFile);
}
}
AfxMessageBox("Second chance");
OpenDocumentFile(_T("D:\\Flaviu\\SampleImages5\\Test.xxx"));
AfxMessageBox("Final ...");
the crashes is occur only after the "final" message box ...
|
|
|
|
|
Did you try doing a Rebuild All like Jochen suggested?
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Of course I did ... something weird is happend ... because if I use only CFileDialog dlgFile(TRUE); in CMyApp::OnFileOpen and the application is crashing down .. I wonder if CFileDialog doesn't have some bug ...
|
|
|
|
|
Sorry, I did not mean to insult you, but when something really weird is going on, Rebuild All is a good thing to do. I wanted to make sure you had tried that because just last week, I had a weird string related problem that I was trying to chase down. Rebuild All was not my first thought, so I ended up spending at least an hour trying to make sense of it before I finally did the rebuild, which fixed the problem.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
I found the problem: the destructor of CFileDialog has problems, and I had solved in follow way: I used CFileDialog variable on the heap, just like this:
CFileDialog* pDlgFile = new CFileDialog(TRUE);
delete pDlgFile;
and everything it's OK now ...
I want to kindly thank you all of you for your interest and patience ! Best wishes for you ! Bye.
modified 5-Apr-13 9:12am.
|
|
|
|
|
Flaviu2 wrote: I found the problem... Moving variables from the stack to the heap is usually not the solution to a problem. You likely just masked it.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Flaviu2 wrote: the destructor of CFileDialog has problem More likely you are referring to a variable that has been destroyed as your dialog has gone out of scope.
Use the best guess
|
|
|
|
|
|
i have problem with CAsyncSocket class when i called listen in widows service application.
i successfully create Thread but my listen fuction didn't work correctly.
here my code..
BOOL CMyThread::InitInstance()
{
while (!AfxSocketInit());
MySocket sock;
while (sock.Create(3005)==SOCKET_ERROR);
while (sock.Listen()==SOCKET_ERROR);
HANDLE file;
file=CreateFile(_T("C:\\initinstance.txt"),GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
CloseHandle(file);
return TRUE;
}
my application create "initinstance.txt" file successfully but when use commmand "netstat -na" port 3005 not listening..
where is my mistake?
|
|
|
|
|
There seems to be no error in the posted code. But the error may be in your MySocket implementation.
You may also delete the file first to ensure that the file has not been created by a previous run.
|
|
|
|
|
thanks for answer my question
i change a little my code like this...
BOOL CMyThread::InitInstance()
{
while (!AfxSocketInit());
MySocket sock;
while (sock.Create(3005)==SOCKET_ERROR);
while (sock.Listen()==SOCKET_ERROR);
HANDLE file;
file=CreateFile(_T("C:\\initinstance.txt"),GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
CloseHandle(file);
Sleep(30000);
return TRUE;
}
socket listening for 30 sec with 6 thread
and after 30 sec thread is 5 and socket is close.
so...
and i understand my thread is closed after that..
here is my code for create thread...
CMyThread* pThread =
(CMyThread*)AfxBeginThread(
RUNTIME_CLASS(CMyThread),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
while(pThread==NULL)
{
Sleep(1);
pThread =
(CMyThread*)AfxBeginThread(
RUNTIME_CLASS(CMyThread),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
}
pThread->ResumeThread();
WaitForSingleObject(pThread->m_hThread,INFINITE);
what do you think? do i have mistake here?
and i'm no sure about calling "WaitForSingleObject(pThread->m_hThread,INFINITE);"
|
|
|
|
|
You are creating a user-interface thread. With socket operations worker threads are usual.
Also, why did you retry to create the thread if the first call fails? This makes no sense.
If the thread creation is done by your main thread, it will be blocked by calling WaitForSingleObject() until the thread terminates.
The skeleton for using a worker thread would look like this:
class CMyClass
{
public:
void StartThread();
protected:
bool m_bKill;
CWinThread *m_pThread;
static UINT ThreadFunc(LPVOID pParam);
};
void CMyClass::StartThread()
{
m_pThread = AfxBeginThread(ThreadFunc, this, THREAD_PRIORITY_NORMAL,
0, CREATE_SUSPENDED);
m_pThread->ResumeThread();
}
UINT CMyClass::ThreadFunc(LPVOID pParam)
{
CMyClass* pThis = reinterpret_cast<CMyClass*>(pParam);
bool bKill = false;
while (!bKill)
{
if (pThis->m_bKill)
break;
}
return 0;
}
|
|
|
|
|
thanks a lot.
Solved
modified 5-Apr-13 9:51am.
|
|
|
|
|
hi all,
on timer function I am step it a progress bar,
when I run the application the timer not working properly, means the progress bar not visible as step it
but when I debug the application its works,
I really don't understand what's happening here.
please help me for this.
|
|
|
|
|
Please ask your question specifically. No one understands your question.
Need more details !
or at least post some source code.
"If A is a success in life, then A=x+y+z. (Work is x; y is play; and z is keeping your mouth shut.)"
|
|
|
|
|
Could you please post the relevant code here?
Veni, vidi, vici.
|
|
|
|
|
So each time the timer fires, you are updating a progress bar, correct? Is that progress bar owned by the same thread that is running the timer? If so, it may be that the paint messages are not being processed. However, without seeing relevant code, I can't say for sure.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
DavidCrow wrote: So each time the timer fires, you are updating a progress bar, correct? Is that
progress bar owned by the same thread that is running the timer?
yes
|
|
|
|
|
IF you dont pubish a short sample of your problem you are very unlikely to recieve an answer to your question.
|
|
|
|
|
if(m_modless == NULL)
{
m_modless = new CModeless(this);
this->EnableWindow(0);
if(!m_modless->Create(IDD_MODELESS, 0))
{
delete m_modless;
m_modless = NULL;
}
m_modless->m_prg2.SetRange32(0,100);
m_modless->m_prg2.SetStep(5);
SetTimer(1111, 50, NULL);
}
void CTestDlg::OnTimer(UINT_PTR nIDEvent)
{
if(nIDEvent==1111)
{
m_modless->m_prg2.StepIt();
}
CDialog::OnTimer(nIDEvent);
}
|
|
|
|