| When user trying to quit program while thread is running |
|
 |
Index ‹ Visual Studio ‹ MFC
|
- Previous
- 1
- Visual Basic >> When using a Frame my embeded contols loose their text?I have a frame with 3 controls on it. 1 text box and 2 option controls. The
text control gets it's text from an INI file and the Option buttons get their
captions from this same ini file when the program loads. For some reason when
the program loads I loose the text and captions? I have been playing around
with the frame settings but have had no luck so I must be missing something
simple right?
- 2
- Mcse >> OT: Beta 2Beta 2 is here!!!
Windows Server 2007 beta 2
Office 2007 beta 2
Vista beta 2
All should be available to anyone, I think!
And yeah, Virtual Server R2 SP1 beta 1, too!
What a great time to be a nerd!
- 3
- MFC >> Debug Assertion FailedFirst the problem, then I'll attempt to post all of the info I think may be pertinent. I get the following message when I try to register a dll on a machine other than the one I built it on
Debug Assertion Failed
Program: C:\B7\DV7333\bin32\REGSVR32.EX
File: olelink.cp
Line: 29
When developing, it builds fine and I am able to register it on the development machine
This is an MFC dll which implements the class wizard generated: DllGetClassObject, DllCanUnloadNow, and DllRegisterServer functions
I have used depends.exe on the target machine and all it's dependcies are accounted for
I have another VB created dll that provides a few classes that are used in this problem dll. I access those via the following statement: #import "vbdll.dll" no_namespac
This stuff I dont really understand, but it appears to work. I do receive the following warning message during the mfc dll build
d:\program files\microsoft visual studio\vc98\include\comip.h(31) : warning C4042: '_IID' : has bad storage clas
d:\program files\microsoft visual studio\vc98\include\comip.h(57) : see reference to class template instantiation '_com_IIID<struct _vbdllObject,&struct __s_GUID _GUID_22b44757_efef_4c0b_be51_32138fe6eb04>' being compile
S:\VC++\dllProject\dllCode.cpp(328) : see reference to class template instantiation '_com_ptr_t<class _com_IIID<struct __vbdllObject,&struct __s_GUID _GUID_22b44757_efef_4c0b_be51_32138fe6eb04>>' being compile
The VB dll IS registered and IS in the path on the target machine
Thanks in advance for any insight into this problem
Jeremy
- 4
- Visual Basic [VB] >> Math.Round and SQL Server RoundI'm trying to determine the best approach for rounding in an application I'm
building. Unfortunately it appears as though SQL Server and VB.NET round in
different ways.
SQL Server
select round(123.465,2)
returns
123.470
Which I think is correct.
VB.NET
Math.Round(123.465, 2)
returns
123.46
Through online help I have read that the VB.NET way of doing it is "called
rounding to nearest, or banker's rounding."
I guess my first question is what is correct (when determining Tax or Sale
prices)?
My next question is what is the best approach for standarizing? Can I make
SQL Server act like VB.NET or VB.NET act like SQL Server?
Are there additional functions either in SQL Server or VB.NET that I am
missing?
Also it appears as if the behavior is consistent throughout the VB.NET
environment (formatcurrency and formatpercent).
There are certain parts of the applicaiton where it makes sense for SQL
Server to calculate some of the numbers and other where it makes sense for
VB.NET to.
Thanks
- 5
- Visual Basic [VB] >> Fill Combobox with DVI would like to fill a combobox with the values of one
column of the dataview I am using. When I set it up the
way I expect it would be, I get every row in the combobox
says: System.Data.DataRowView
If I click on one, it navigates to the right place. Any
idea how I would get the System.Data.DataRowView to show
the actual values in the column?
Thanks
- 6
- 7
- 8
- Visual Basic [VB] >> Share source files among projects?Is it possible to share a single source file among two or more Projects in a
Solution?
I'm not talking about a DLL, just a .vb file that might contain a class or
module with common code to be compiled into each project. That way this
code can be updated once instead of makiing duplicate changes to identical
code within each project.
I have tried putting the source in a common folder, then using Add Existing
Item to add it to each project, but that creates a separate copy of the file
in each project folder. Then I'm back to keeping changes syncronized
manually.
I have been searching VB.NET help and newsgroups, but either this can't be
done or I am asking the wrong questions.
thanks
Dick
- 9
- Visual Basic >> Profiler in Team Edn for S/W Dev--Any successes?I am struggling to get any useful performance data out of the profiling tool
in Visual Studio Team Edition for Software Developers.
On a simple command-line app, it reports bogus call paths in release and
release with debug info builds. With a debug build, the results are so
compromised by the overhead of calling inline functions that they are useless.
With a real-world, complex app, it either runs out of memory trying to
analyze the profile data or crashes. This is for an app that runs in 1.2
seconds normally.
It won't even run the app if you select sampling; profiling must be done
with instrumented code.
I've used MetroWerks Hierarchical Profiler, Rational Quantify and Compware
DevPartner, and all have provided useful information that have enabled me to
track down, understand and fix performance problems. Not so Visual Studio
Team Edition. Is there some trick that makes it work usefully?
Thanks,
Rich
- 10
- Visual Basic [VB] >> ADO in VB.NETHi
I want to apply ADO object in VB.NET. Can I bind the textbox, editmask,
combo box and grid control to the ADO recordset?
Any sample would be appreciated.
Thanks...Douglas
- 11
- VB Scripts >> Run MBSA tool as administrator?Hi folks,
I have a logon vbscript to run the MBSA tool, but it apparently needs
to be ran with admin privledges. I know there are 3rd party utilities
that can help do this, but I'd rather just incorporate the necessary
info into my script. I've seen people mention how to do this, but I'm a
little confused about how to incorporate this into my script. Here's my
script:
Sub run_mbsa
Set oShell = WScript.CreateObject ("WSCript.shell")
return = oShell.Run("""C:\Program Files\Microsoft Baseline Security
Analyzer\mbsacli.exe"" /c %computername% /o %C%.%D%.com.xml /f
c:\output.txt", 0, true)
Set objFSO = CreateObject("Scripting.FileSystemObject")
xmlfiles = oShell.ExpandEnvironmentStrings("%userprofile%") +
"\securityscans\*.xml"
objFSO.CopyFile xmlfiles, "\\servername\foldername" , True
objFSO.DeleteFile xmlfiles
Set oShell = Nothing
Set objFSO = Nothing
End Sub
Can someone tell me how to run this as an admin?
Thank you,
Ed
- 12
- MFC >> questin about enum all threads of a processHi all:
I know I can enum the threads of a process using toolhelper lib in win2k
or win9x. but the lib is not availble at Winnt. instead of toolhelper,
microsoft supply the performance data library, but the data struct is too
complex. Can I have another way to get all threads handle of a process?
Thank advance.
sincecely
- 13
- Visual Basic [VB] >> Serial Comm ProblemI wrote a program that communicate with SerialComm. In every 300
milliseconds, my program continuously send & receive data via the serial
port once the program starts.
My program is once in a while, the serial port seems corrupted because when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.
Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?
Thanks!
Michael
- 14
- 15
- MFC >> Fatloss computer programI have been using this computer program for a couple weeks now and i am very pleased with the results so far. its a software fatloss program, if your looking for a diet/weightloss plan i reccomend you check this place out first: http://fatloss9.50webs.com
|
| Author |
Message |
raghava

|
Posted: Thu Jun 23 18:58:41 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
Hi guys, I have a memory leak problem. When I tried to quit program by click
'x' at top right corner while my ui thread and its child worker thread are
running, debugger display following messages:
The thread 0x570 has exited with code 0 (0x0).
The thread 0x574 has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8, 4
bytes long.
a CWinThread object at $00C17BF0, 112 bytes long
c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0, 12
bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398, 12
bytes long.
Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
subtype 0, 128 bytes long.
a CMyUIThread object at $00C17E40, 128 bytes long
Object dump complete.
The thread 0x304 has exited with code 0 (0x0).
The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
(0x0).
In my program, ui thread is created when certain selection made from combo
box and shutdown, deleted when combo box selection. Ui thread creates one
worker thread for communication with embeded system via COM port. So in a
normal situation(combo box changed), shutdown prccedure is like this: First,
main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
flag to FALSE to let worker thread exit its while(running) loop. Just before
exit, worker thread sends another QUIT packet to embeded system to power off
then PostMessage(THREAD_QUIT) to main frame. Message handler in main frame
wait for m_hThread and delete pThread. Debugger doesn't complain about this
normal shutdown and the program looks just fine when I try without debugger.
Can I neglect this situation?
Where can I insert this shutdown procedure when program is forced to quit
while threads running?
Any suggestion appreciated. Cheers
Visual Studio344
|
| |
|
| |
 |
Scott

|
Posted: Thu Jun 23 18:58:41 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
bbg wrote:
> Hi guys, I have a memory leak problem. When I tried to quit program by click
> 'x' at top right corner while my ui thread and its child worker thread are
> running, debugger display following messages:
>
> The thread 0x570 has exited with code 0 (0x0).
> The thread 0x574 has exited with code 0 (0x0).
> Detected memory leaks!
> Dumping objects ->
> c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8, 4
> bytes long.
> a CWinThread object at $00C17BF0, 112 bytes long
> c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0, 12
> bytes long.
> Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
> c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398, 12
> bytes long.
> Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
> c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
> subtype 0, 128 bytes long.
> a CMyUIThread object at $00C17E40, 128 bytes long
> Object dump complete.
> The thread 0x304 has exited with code 0 (0x0).
> The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
> (0x0).
>
> In my program, ui thread is created when certain selection made from combo
> box and shutdown, deleted when combo box selection. Ui thread creates one
> worker thread for communication with embeded system via COM port. So in a
> normal situation(combo box changed), shutdown prccedure is like this: First,
> main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
> flag to FALSE to let worker thread exit its while(running) loop. Just before
> exit, worker thread sends another QUIT packet to embeded system to power off
> then PostMessage(THREAD_QUIT) to main frame. Message handler in main frame
> wait for m_hThread and delete pThread. Debugger doesn't complain about this
> normal shutdown and the program looks just fine when I try without debugger.
> Can I neglect this situation?
> Where can I insert this shutdown procedure when program is forced to quit
> while threads running?
> Any suggestion appreciated. Cheers
Handle the WM_CLOSE message in CMainFrame. It is sent when the user
clicks the 'X' close button. Start the thread shutdown sequence, then
either postpone the close by not calling CFrameWnd::OnClose until you
have received your THREAD_QUIT message, or use WaitForMultipleObjects to
wait for the thread handles before calling CFrameWnd::OnClose.
--
Scott McPhillips [VC++ MVP]
|
| |
|
| |
 |
Joseph

|
Posted: Thu Jun 23 17:50:30 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
It is your responsibility to make sure that all threads cleanly terminate. How do you mean
that a thread is "deleted"?
Note that setting a running flag to FALSE for a worker thread works only if the thread in
question is (a) compute bound in a tight loop, and polling for the flag or (b) has a way
to come out of a wait and check the flag.
What is QUIT? A user-defined message, or is it WM_QUIT? If it is a user-defined message,
you should probably use a better name, such as UWM_QUIT or something like that.
What was allocated in MyUIThread.cpp(396)? At mainfrm.cpp(746)? etc. It looks suspicious;
I'd worry about it, and would try to solve it by trying to make sure that all values were
properly freed.
joe
On Fri, 24 Jun 2005 10:17:55 +1200, "bbg" <EMail@HideDomain.com> wrote:
>Hi guys, I have a memory leak problem. When I tried to quit program by click
>'x' at top right corner while my ui thread and its child worker thread are
>running, debugger display following messages:
>
>The thread 0x570 has exited with code 0 (0x0).
>The thread 0x574 has exited with code 0 (0x0).
>Detected memory leaks!
>Dumping objects ->
>c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8, 4
>bytes long.
>a CWinThread object at $00C17BF0, 112 bytes long
>c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0, 12
>bytes long.
> Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
>c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398, 12
>bytes long.
> Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
>c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
>subtype 0, 128 bytes long.
>a CMyUIThread object at $00C17E40, 128 bytes long
>Object dump complete.
>The thread 0x304 has exited with code 0 (0x0).
>The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
>(0x0).
>
>In my program, ui thread is created when certain selection made from combo
>box and shutdown, deleted when combo box selection. Ui thread creates one
>worker thread for communication with embeded system via COM port. So in a
>normal situation(combo box changed), shutdown prccedure is like this: First,
>main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
>flag to FALSE to let worker thread exit its while(running) loop. Just before
>exit, worker thread sends another QUIT packet to embeded system to power off
>then PostMessage(THREAD_QUIT) to main frame. Message handler in main frame
>wait for m_hThread and delete pThread. Debugger doesn't complain about this
>normal shutdown and the program looks just fine when I try without debugger.
>Can I neglect this situation?
>Where can I insert this shutdown procedure when program is forced to quit
>while threads running?
>Any suggestion appreciated. Cheers
>
Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
|
| |
|
| |
 |
bbg

|
Posted: Sun Jun 26 16:17:11 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
Thank you Scott for your pin-point answer. I will start to write code like
this:
void CMainFrame::OnClose()
{
if (COMBO_SELECTION == SELECTION_1)
{
//......
}
else
CFrameWnd::OnClose();
}
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:EMail@HideDomain.com...
> bbg wrote:
>
> > Hi guys, I have a memory leak problem. When I tried to quit program by
click
> > 'x' at top right corner while my ui thread and its child worker thread
are
> > running, debugger display following messages:
> >
> > The thread 0x570 has exited with code 0 (0x0).
> > The thread 0x574 has exited with code 0 (0x0).
> > Detected memory leaks!
> > Dumping objects ->
> > c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at
0x00C17CA8, 4
> > bytes long.
> > a CWinThread object at $00C17BF0, 112 bytes long
> > c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0,
12
> > bytes long.
> > Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
> > c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398,
12
> > bytes long.
> > Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
> > c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
> > subtype 0, 128 bytes long.
> > a CMyUIThread object at $00C17E40, 128 bytes long
> > Object dump complete.
> > The thread 0x304 has exited with code 0 (0x0).
> > The program c:\work\MyProject\Debug\MyProject.exe' has exited with code
0
> > (0x0).
> >
> > In my program, ui thread is created when certain selection made from
combo
> > box and shutdown, deleted when combo box selection. Ui thread creates
one
> > worker thread for communication with embeded system via COM port. So in
a
> > normal situation(combo box changed), shutdown prccedure is like this:
First,
> > main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
> > flag to FALSE to let worker thread exit its while(running) loop. Just
before
> > exit, worker thread sends another QUIT packet to embeded system to power
off
> > then PostMessage(THREAD_QUIT) to main frame. Message handler in main
frame
> > wait for m_hThread and delete pThread. Debugger doesn't complain about
this
> > normal shutdown and the program looks just fine when I try without
debugger.
> > Can I neglect this situation?
> > Where can I insert this shutdown procedure when program is forced to
quit
> > while threads running?
> > Any suggestion appreciated. Cheers
>
> Handle the WM_CLOSE message in CMainFrame. It is sent when the user
> clicks the 'X' close button. Start the thread shutdown sequence, then
> either postpone the close by not calling CFrameWnd::OnClose until you
> have received your THREAD_QUIT message, or use WaitForMultipleObjects to
> wait for the thread handles before calling CFrameWnd::OnClose.
>
> --
> Scott McPhillips [VC++ MVP]
>
|
| |
|
| |
 |
bbg

|
Posted: Sun Jun 26 16:56:13 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
Joe, I'm greatly depending on knowledges obtained from your essays when
writing threads codes, many appreciates for sharing your know-hows.
> It is your responsibility to make sure that all threads cleanly terminate.
How do you mean
> that a thread is "deleted"?
When combo selection changed to other one, main frame sends following
message to ui thread to shutdown threads:
pMyUIThread->PostThreadMessage(UWM_BUTTON_PRESSED,
(WPARAM)(BYTE)QUIT,0);
Then ui thread set some volatile flag so that worker thread detects it and
set running flag to FALSE to exit while loop.
Worker thread also send back following message to main frame:
AfxGetMainWnd()->PostMessage(UWM_THREAD_1,
(WPARAM)(BYTE)THREAD_1_QUIT,0);
Then main frame's thread message handler may think that worker thread has
shutdown and does following jobs to terminate ui thread:
LRESULT CMainFrame::OnThreadMessage(WPARAM wParam, LPARAM lParam)
{
BYTE WhatHappened = (BYTE)wParam;
//...........
else if (WhatHappened == THREAD_DISPLAY_STATUS_INFO)
{
CString * s = (CString *)lParam;
m_wndStatusBar.SetPaneText (1, *s, TRUE);
delete s;
}
else if (WhatHappened == THREAD_QUIT)
{
pMyUIThread->PostThreadMessage(WM_QUIT, 0, 0); // as you recomended...
it works well in not 'X' button case
VERIFY(WaitForSingleObject(pMyUIThread->m_hThread, INFINITE) ==
WAIT_OBJECT_0);
delete pMyUIThread;
}
return 0;
}
Now, I'm trying to write CMainFrame::OnClose() to handle 'X' button case and
trouble is that....
In my shutodwn method, main frame may know when it can send WM_QUIT to
terminate ui thread by waiting message from worker thread.
But in 'X' button case, message handler doesn't have a chance to handle that
message, so codes below are not working properly.
void CMainFrame::OnClose()
{
if (COMBO_SELECTION == CHOICE_1) // if ui/worker threads were working,
try to shutdown them
{
// send QUIT to MyUIThread to shutdown worker thread and ui thread itself
pMyUIThread->PostThreadMessage(UWM_BUTTON_PRESSED, (WPARAM)(BYTE)QUIT,0);
// MyUIThread will send back UWM_THREAD_MSG(QUIT).
// But no chance to be handled in 'X' button case
pMyUIThread->PostThreadMessage(WM_QUIT, 0, 0);
VERIFY(WaitForSingleObject(pMyUIThread->m_hThread, INFINITE) ==
WAIT_OBJECT_0);
delete pMyUIThread;
}
else
CFrameWnd::OnClose();
}
Thanks
bbg
> On Fri, 24 Jun 2005 10:17:55 +1200, "bbg" <EMail@HideDomain.com>
wrote:
>
> >Hi guys, I have a memory leak problem. When I tried to quit program by
click
> >'x' at top right corner while my ui thread and its child worker thread
are
> >running, debugger display following messages:
> >
> >The thread 0x570 has exited with code 0 (0x0).
> >The thread 0x574 has exited with code 0 (0x0).
> >Detected memory leaks!
> >Dumping objects ->
> >c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8,
4
> >bytes long.
> >a CWinThread object at $00C17BF0, 112 bytes long
> >c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0,
12
> >bytes long.
> > Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
> >c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398,
12
> >bytes long.
> > Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
> >c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
> >subtype 0, 128 bytes long.
> >a CMyUIThread object at $00C17E40, 128 bytes long
> >Object dump complete.
> >The thread 0x304 has exited with code 0 (0x0).
> >The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
> >(0x0).
> >
> >In my program, ui thread is created when certain selection made from
combo
> >box and shutdown, deleted when combo box selection. Ui thread creates one
> >worker thread for communication with embeded system via COM port. So in a
> >normal situation(combo box changed), shutdown prccedure is like this:
First,
> >main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
> >flag to FALSE to let worker thread exit its while(running) loop. Just
before
> >exit, worker thread sends another QUIT packet to embeded system to power
off
> >then PostMessage(THREAD_QUIT) to main frame. Message handler in main
frame
> >wait for m_hThread and delete pThread. Debugger doesn't complain about
this
> >normal shutdown and the program looks just fine when I try without
debugger.
> >Can I neglect this situation?
> >Where can I insert this shutdown procedure when program is forced to quit
> >while threads running?
> >Any suggestion appreciated. Cheers
> >
>
> Joseph M. Newcomer [MVP]
> email: EMail@HideDomain.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
|
| |
|
| |
 |
Joseph

|
Posted: Sun Jun 26 22:18:29 CDT 2005 |
Top |
MFC >> When user trying to quit program while thread is running
See below...
On Mon, 27 Jun 2005 09:56:13 +1200, "bbg" <EMail@HideDomain.com> wrote:
>Joe, I'm greatly depending on knowledges obtained from your essays when
>writing threads codes, many appreciates for sharing your know-hows.
>
>> It is your responsibility to make sure that all threads cleanly terminate.
>How do you mean
>> that a thread is "deleted"?
>
>When combo selection changed to other one, main frame sends following
>message to ui thread to shutdown threads:
>
> pMyUIThread->PostThreadMessage(UWM_BUTTON_PRESSED,
>(WPARAM)(BYTE)QUIT,0);
****
Note that the thread must be blocked on the message pump GetMessage to see this. If the
thread is off doing some long computation, this will not be seen until the computation
finishes.
If it does as you say and sets a volatile flag, then the worker thread will, if it
properly polls this flag, terminate.
****
>
>Then ui thread set some volatile flag so that worker thread detects it and
>set running flag to FALSE to exit while loop.
>Worker thread also send back following message to main frame:
>
> AfxGetMainWnd()->PostMessage(UWM_THREAD_1,
>(WPARAM)(BYTE)THREAD_1_QUIT,0);
****
Be careful about AfxGetMainWnd() in worker threads; it doesn't always give you the main
window. I tend to do
::PostMessage(AfxGetApp()->m_hWnd, ...)
or better still, pass the CWnd * object in so I can just call its methods directly
****
>
>Then main frame's thread message handler may think that worker thread has
>shutdown and does following jobs to terminate ui thread:
>
>LRESULT CMainFrame::OnThreadMessage(WPARAM wParam, LPARAM lParam)
>{
> BYTE WhatHappened = (BYTE)wParam;
> //...........
> else if (WhatHappened == THREAD_DISPLAY_STATUS_INFO)
> {
> CString * s = (CString *)lParam;
> m_wndStatusBar.SetPaneText (1, *s, TRUE);
> delete s;
> }
> else if (WhatHappened == THREAD_QUIT)
> {
> pMyUIThread->PostThreadMessage(WM_QUIT, 0, 0); // as you recomended...
>it works well in not 'X' button case
> VERIFY(WaitForSingleObject(pMyUIThread->m_hThread, INFINITE) ==
>WAIT_OBJECT_0);
> delete pMyUIThread;
****
Only if you have set m_bAutoDelete to FALSE. This requires creating the thread suspended,
setting the m_bAutoDelete = FALSE, then doing a ResumeThread. Otherwise the delete will
likely result in a serious error as you try to delete a piece of storage the second time.
***
> }
> return 0;
>}
>
>Now, I'm trying to write CMainFrame::OnClose() to handle 'X' button case and
>trouble is that....
>In my shutodwn method, main frame may know when it can send WM_QUIT to
>terminate ui thread by waiting message from worker thread.
>But in 'X' button case, message handler doesn't have a chance to handle that
>message, so codes below are not working properly.
****
The [x] button should be generated a WM_CLOSE message, so you should be hitting the
OnClose handler. Can you verify this with the debugger?
****
>
>void CMainFrame::OnClose()
>{
> if (COMBO_SELECTION == CHOICE_1) // if ui/worker threads were working,
>try to shutdown them
****
Be very cautious of this sort of code; you shouldn't be checking the combo box, you should
be checking to see if there is a thread-running state. Note that in multiple languages,
the choices may be ordered differently. And what happens if the user changes the combo box
setting, then hits the close box while the thread is shutting down?
***
> {
> // send QUIT to MyUIThread to shutdown worker thread and ui thread itself
> pMyUIThread->PostThreadMessage(UWM_BUTTON_PRESSED, (WPARAM)(BYTE)QUIT,0);
> // MyUIThread will send back UWM_THREAD_MSG(QUIT).
> // But no chance to be handled in 'X' button case
> pMyUIThread->PostThreadMessage(WM_QUIT, 0, 0);
> VERIFY(WaitForSingleObject(pMyUIThread->m_hThread, INFINITE) ==
>WAIT_OBJECT_0);
> delete pMyUIThread;
****
Same problem with m_bAutoDelete. Note that even doing the WaitForSingleObject may fail
horribly because the thread may have finished, and deleted the object pMyUIThread
references, and they you try to use it to point to something else. Not a good idea unless
you have made sure that m_bAutoDelete is FALSE (if it isn't, this code could crash in a
rather nasty number of ways)
My own preference these days would be to simply set a flag saying "shutdown in progress"
and return, instead of doing the WaitFor. Any attempt to use any menu item would make sure
the menu item was disabled. Then when the thread message was received by the mainframe
that ALL threads were finished, then you call CFrameWnd::OnClose.
****
> }
> else
> CFrameWnd::OnClose();
>}
>
>Thanks
>bbg
>
>> On Fri, 24 Jun 2005 10:17:55 +1200, "bbg" <EMail@HideDomain.com>
>wrote:
>>
>> >Hi guys, I have a memory leak problem. When I tried to quit program by
>click
>> >'x' at top right corner while my ui thread and its child worker thread
>are
>> >running, debugger display following messages:
>> >
>> >The thread 0x570 has exited with code 0 (0x0).
>> >The thread 0x574 has exited with code 0 (0x0).
>> >Detected memory leaks!
>> >Dumping objects ->
>> >c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8,
>4
>> >bytes long.
>> >a CWinThread object at $00C17BF0, 112 bytes long
>> >c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0,
>12
>> >bytes long.
>> > Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
>> >c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398,
>12
>> >bytes long.
>> > Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
>> >c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
>> >subtype 0, 128 bytes long.
>> >a CMyUIThread object at $00C17E40, 128 bytes long
>> >Object dump complete.
>> >The thread 0x304 has exited with code 0 (0x0).
>> >The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
>> >(0x0).
>> >
>> >In my program, ui thread is created when certain selection made from
>combo
>> >box and shutdown, deleted when combo box selection. Ui thread creates one
>> >worker thread for communication with embeded system via COM port. So in a
>> >normal situation(combo box changed), shutdown prccedure is like this:
>First,
>> >main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
>> >flag to FALSE to let worker thread exit its while(running) loop. Just
>before
>> >exit, worker thread sends another QUIT packet to embeded system to power
>off
>> >then PostMessage(THREAD_QUIT) to main frame. Message handler in main
>frame
>> >wait for m_hThread and delete pThread. Debugger doesn't complain about
>this
>> >normal shutdown and the program looks just fine when I try without
>debugger.
>> >Can I neglect this situation?
>> >Where can I insert this shutdown procedure when program is forced to quit
>> >while threads running?
>> >Any suggestion appreciated. Cheers
>> >
>>
>> Joseph M. Newcomer [MVP]
>> email: EMail@HideDomain.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
>
Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
|
| |
|
| |
 |
| |
 |
Index ‹ Visual Studio ‹ MFC |
- Next
- 1
- Visual Studio C++ >> Simple question about dllimportI've got a h file for a usb device that has definitions of function exported
from a dll. An example would be (with #defines translated):
extern "C" __declspec(dllimport) int __stdcall FT_Open(int deviceNumber, int
*pHandle);
but where is the actual dll filename specified so my program knows where to
find it?
Thanks,
Michael
- 2
- Visual Basic >> Calling a Macro from another workbookHi,
Yes I have read up on the different ways of doing this, but I always
come to the same problem.
In my current code I have the line
Application.Run ("T1Seed1.xls!Main")
Which works fine (it calls the "Main" macro in T1Seed2.xls). But once
the "main" macro is run, the rest of my current macro doesn't run.
Here is my code (missing some variables thata bit above, but thats
ok).
Dim ESDUFile, RootPath, WorkBookToOpen, SheetToOpen, BuildingHeight As
String
ESDUFile = Sheets("Rotate spf red").Cells(10, 9)
RootPath = ESDUFile
Do While Right(RootPath, 1) <> "\"
RootPath = Left(RootPath, Len(RootPath) - 1)
Loop
BuildingHeight = 225
SeedScale = 345
For A = 1 To NumTowers
For B = 1 To 2
SheetToOpen = "T" & A & "Seed" & B & ".xls"
WorkBookToOpen = RootPath & SheetToOpen
FileCopy ESDUFile, WorkBookToOpen
Range("C22:C57").Copy
Workbooks.Open WorkBookToOpen
Windows(SheetToOpen).Activate
Sheets("RWDI_Factors").Select
Range("H67").Select
ActiveSheet.Paste
Range("D7") = SeedScale
Range("D6") = BuildingHeight
Application.Run ("T1Seed1.xls!Main")
Sheets("Factors").Select
Application.CutCopyMode = False 'closes the clipboard with massive
amounts of data thus does not prompt to save or close
ActiveWorkbook.Close True ' false means not to save, true means to
save and close
Windows("MR_Setup_underDevelopment_profiles.xls").Activate
Next B
Next A
It works fine up until right after the Application.Run line where it
will not continue on (ie it will not select the "Factors" sheet or do
anything after).
Is there another way I can do this that will allow the original macro
to continue running after it calls the macro in the other workbook?
Any help would be appreciated.
Jack
- 3
- MFC >> ActiveX in MFCI'm trying to create an ActiveX control in MFC.
I have a library which was provided for the development of an MFC program
NOT ActiveX.
I made a sample ActiveX and included the library under
Project->Settings->Link Tab but after building the ActiveX and viewing the
control in Test Container, no methods were exposed??
Am I doing something wrong or will the library NOT work with an ActiveX???
Thanks
David
- 4
- Visual Studio C++ >> bit shiftingi wanna shift the unsigned int e.g.
from
BINARY: 0110 0000 0011 0000 1101 0000 0000 0001
into
BINARY: 1000 0000 0000 0100 0000 0000 0000 0000
with the code i << 18;
but it seems that it won't detected the leading zero during shifting ?
and wrongly give me
0100 0000 0000 0100 0000 0000 0000 0000
any solution for that ?~
- 5
- Visual Basic >> compiling the entire thingHi guys...
Here's a quick query...
I have almost finished making my first project in vb...
But I am confused...as to how should i compile the entire project and make a
setup ...
i know how to make the exe files...
I searched through MSDN but couldn't get much info...
And does the setup do everything ?...I mean what about the DSNs I created in
Control Panel, and what about my entire database ?...is that also properly
installed with the setup ?...
And how do i start doing it ?....
Please help...
thanks..
anupam
anupam@anupamjain.com
- 6
- Visual Basic >> Icon size problemHello,
My program's frmAbout has an icon. The ico file has the same icon in two
sizes, 16 x 16 and 32 x 32 pixels. I don't want the smaller one to be
displayed to users. So, the size should be 32 x 32 pixels.
Anyway, on some computers the icon will be displayed in size 16 x 16
pixels. How could I prevent this?
The ico file is dislayed in picIcon which is a PictureBox element. Its
ScaleMode is "Pixel", AutoDraw is "False", and AutoSize is "False".
The ScaleMode value of frmAbout is "Twip".
What should I do?
Thanks,
Mika
- 7
- Visual Studio C++ >> How to convert _TCHAR * to string?I need to check command line parameter
if (argv[1] == option) .... // option is a string variable
And argv is defined as _TCHAR* argv[] by MSVS wizard.
The code don't work and it's very hard to convert argv[1] to string.
- 8
- 9
- Visual Basic >> ErrorsDear All,
Does anyone know of a third party tool that can add error handling code to
all subs/functions in a class or module to a specified format which then can
be customised to deal with the errors likely to be raised at the code?
I have been neglectful in adding error handling code and comments as I go as
the project has now grown and other developers are going to be using my
code. I know that it is bad practice and I have learned my lesson, but any
advice, other than its your own fault, would be most welcome. If I have to
create my own add-in for the future, can anyone suggest how I can
programatically find the start and end of a sub to add the suggested code?
Thanks again.
Alastair MacFarlane
- 10
- Visual Basic >> "Reading emails from All Public folders"Hi,
I am developing a vb application to read the latest arrived mail from
"All public folders" through outlook. This should be dynamic as the
folders increase in the "All Public folders", The program should read
the folders accordingly.
Can anyone help on this.
- 11
- VB Scripts >> force clicking on an objectHello,
How can I force clicking on an object,
if I have the following code, and I want to do click on event_view -
How can I do that ?
Thanks :)
The code :
-------------
<input type="hidden" id="event_view" onclick = "myview" />
...
- 12
- 13
- Visual Studio C++ >> Problem with covariant return typesThe following code won't compile (error C2555: 'B::f': overriding virtual
function return type differs and is not covariant from 'A::f') unless I
moved the definitions of X and Y to before the definitions of A and B
respectively. Now I can understand that the compiler doesn't know that Y is
derived from X when parsing B but at the very least this is a very confusing
error message and I'm not sure it shouldn't be accepted.
Rob.
class X;
class A
{
public:
virtual X* f () const = 0;
};
class X
{
public:
};
class Y;
class B : public A
{
public:
virtual Y* f () const;
};
class Y : public X
{
public:
};
- 14
- Visual Basic [VB] >> TUTORIALS ON COMPUTER PROGRAMMINGlanguages Have the complete details regarding programming languages.
A-Z about programming languages like Java J2EE, C++, code
implementation guides and more.
http://operatingsys.blogspot.com/
Google.com is not only a search engine but also does webadvertising
through websites and blogs.
Lakhs of common people are earning hundreds of dollars through online
advertising.
It also has other products like chatting,google earth,google talk etc.
Genuine Internet jobs for all. Earn Unlimited income.visit
http://googlepromisesyou.blogspot.com/
- 15
- MFC >> VC2008 dpiaware manifest?When you create a new MFC application with the wizard in VC2008 you will see
the following code in stdafx.h:
#pragma comment(linker,"/manifestdependency:\"type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
What do you write in stdafx.h to add the dpiaware manifest (se below) the
same way?
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
Best regards from Gaute
|
|
|