|
|
|
|
Hi,
I tried to create a dialog (Modal) based application using win32. It is working but
at close button not able to close.
It is disappearing but not closing properly..my mean to say is that running behind..I checked with Task Manager.
Code for CallBack procedure is as:
BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, wParam);
return (INT_PTR)TRUE;
}
break;
What is the wrong?
|
|
|
|
|
My guess is that your main message loop keeps on going. Just because you close a dialog the program's message loop won't quit. Depending on your implementation you need to somehow tell the loop to stop processing messages, for example by using PostQuitMessage[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
I have a thread, it is has a normal priority, when it starts to excute, it runs for 5 or 6 seconds then stops for 3 or 4 seconds and run again, stops again this goes till it finishes his work. Any idea why this happens, programm code is in Visual C++.
Thanks
|
|
|
|
|
Isn't that (being scheduled) the normal thread beahviour?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i changed the thread priority to HIGHEST, but it didi not help.
|
|
|
|
|
Simply don't do that. It is normal for threads being scheduled.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Being scheduled is normal thread behaviour! But it's not a normal thread behaviour to wait 3-5 seconds to get the next time slice!
Greetings
Covean
|
|
|
|
|
True but it really depends on how those 3-5 seconds come out? Are they just a OP impression? How did she measure them?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes there you are right. But in normal nobody should notice the thread-switches (if the thread and the process doesn't have the lowest priority or many real-time priority processes are running), so I would assume that the op has a real problem with it, no matter if the thread pauses for 300-500ms or 3-5s.
Greetings
Covean
|
|
|
|
|
use function Sleep(n_time).
|
|
|
|
|
Uh?!
OP missed?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I prefer you to read chapter 2. Processes and threads from "Modern Operating Systems" by Andrew S Tannenbaum.
It will be useful for you.
Величие не Бога может быть недооценена.
|
|
|
|
|
Can you please post your threads code to see if they are waiting for some reason.
Edit: Did some typo.
Greetings
Covean
|
|
|
|
|
void CMyThread::ThreadStart()
{
if (m_pSelThread != NULL) // CWinThread* m_pSelThread;
{
if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0)
return;
delete m_pSelThread;
m_pSelThread = NULL;
}
m_pSelThread = AfxBeginThread((AFX_THREADPROC)ThreadFunction, this, THREAD_PRIORITY_NORMAL, 0,CREATE_SUSPENDED);
m_pSelThread->m_bAutoDelete = FALSE;
m_pSelThread->ResumeThread();
}
UINT CMyThread::ThreadFunction
(
LPVOID param
)
{
while(!bTerminate) // bool bTerminate
{
if ((::WaitForSingleObject(m_Sel_End_Event, 0) == WAIT_OBJECT_0))
{
bTerminate = true;
continue;
}
}
|
|
|
|
|
I couldn't find any reason why your thread pauses for 3-5 seconds.
But your "main loop" is a kind of resource-eating.
Do you really meant to use a timeout of 0 to wait for this object?
0 timeout means to check the signaled state of the waitable handle
and to return immediately. So your loop will iterate very very fast and
consumes nearly 100% processing time.
UINT CMyThread::ThreadFunction(LPVOID param)
{
while(!bTerminate)
{
if ((::WaitForSingleObject(m_Sel_End_Event, 0) == WAIT_OBJECT_0))
{
bTerminate = true;
continue;
}
}
}
But as I said before this doesn't solve your problem. Is there maybe more code you can provide?
By the way you also use the 0 timeout also in your ThreadStart function (but there it shouldn't be
a problem).
Greetings
Covean
|
|
|
|
|
Hi to everybody.
I have used a Regular DLL in VC++ (ver 6.0) but i have some problems when i use the object.
I have create a new object:
"CObOggetto*pOggettoDaRibaltare = new CObOggetto;"
but when i try to use the variables into the object ...
pOggetto->m_sCodiceContratto = "000001";
the application crash like a the pointer is not allocated!!!
The variables are all CString.
Can you help me???
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
Sorry!!!
The code are this:
"CObOggetto*pOggetto = new CObOggetto;"
but when i try to use the variables into the object ...
pOggetto->m_sCodiceContratto = "000001";
Can you help me???
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
You will need to give a lot more information. The fact that the object is created and used within the DLL is not a problem. So, make sure that the object is not destroyed after you allocated it and that you are manipulating the same object.
Could you post some more relevant piece of code ?
Just a guess: is this pOggetto variable a member of another object, or is it local to a function (created, used and then destroyed at the end of the function) ? I would guess that you are declaring a class variable and then creating a variable with the same name in a function (which of course would leave the class variable unitialized).
|
|
|
|
|
Can you debug and check if pOggetto is NULL?
|
|
|
|
|
Hi
Yes. The pointer is null.
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
It is crashing because the program is accessing a member variable by using a NULL pointer. So, the question is why new is returning a NULL pointer. Is the class constructor is trying to allocate a very large block of memory which the system cannot satisfy?
Can you check (debug into) CObOggetto's constructor and see what it does?
|
|
|
|