|
Hi.
I have discovered a problem with multithreading processes in my program. Here is an example.
- program starts
- CMyProgramApp::InitInstance() calls RestoreState() in CMainFrame()
- RestoreState() restores the windows positions via registry
- RestoreState() restores data (int, char, binary, etc) from registry to variables in CMyProgramDoc()
- RestoreState() calls a function in CMyProgramDoc() which begins a worker thread
- worker thread does some calculation
Problem: For some reason, I have found that if the calculation is big i.e. it takes a long time, the thread never gets closed and deleted.
The worker thread PostMessage main frame a message indicating that it is done. However, sometimes main frame never received the message!
-----
UINT WorkerThreadFunc(LPVOID pParam)
{
...
pWnd->PostMessage(WM_USER_WORKERTHREAD_CLOSED, 0, 0);
return 0;
-----
There is a handler in main frame to handle the message that class a function in doc to close the worker thread; however, I found that if the worker thread takes a long time to finish a calculation, main frame never receive or ignores the PostMessage.
The only problem I can think of right now is I am starting the worker thread too early. In other words, I should start the worker thread after the program has started and all window positions have been restored.
Do you see any other flaws? Please post.
Thanks,
Kuphryn
|
|
|
|
|
Okay.
Damn. The problem was not anything except bad debugging. I made a small mistake that caused a program loop inside the worker thread. The worker thread never PostMessage! It there is a loop that never exits.
The solution was to reset one of the variables I used inside the while look.
The breakpoint feature in Visual C++ is extremely useful!.
Special thanks to IndirectX of GameDev for breaking up the subject about breakpoint.
Kuphryn
|
|
|
|
|
OK, i need to make a dll that will add an entry to the windows explorer context menu, i had a look at this article on codeproject but found that I could not make sense of the code, that i need and know is in there. Cananyone help me out?
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I think Microsoft has invented A.I. My computer has a mind of its own!"
|
|
|
|
|
look around a bit on this site... there are a ton of articles on shell extensions.
-c
Cheap oil. It's worth it!
|
|
|
|
|
I have tutorials [part 1 and part 2] on this subject. Maybe a tutorial format will be easier for you to digest.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.10414 AcidHelm
|
|
|
|
|
I saw your tutorials soon after I made this thread. IT was just right for me, understood it ( 'cos its made for idiots )
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I think Microsoft has invented A.I. My computer has a mind of its own!"
|
|
|
|
|
Michael Dunn wrote:
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
you know, i dont think you should be advertising your own software (shareware i might add) on codeproject, unless its one of those big banners, am i right?
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I think Microsoft has invented A.I. My computer has a mind of its own!"
|
|
|
|
|
No, it's acceptable here to pimp your own stuff in your signature. Else I wouldn't be doing it.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.10414 AcidHelm
|
|
|
|
|
I can't find how can I use WM_ONKEYDOWN or WM_ONSYSKEYDOWN when I 've somme buttons on my
application. If I erase them, it workds perfectly, but either not...
If I have buttons, they take the input focus, and I can't find the way to keep the focus on my
window
|
|
|
|
|
|
Hi people,
I'm trying to change the font used to draw in my view class, but there's something wrong. This is the code in my view's OnDraw handler:
CFont NewFont;
LOGFONT LogFont;
GetFont()->GetLogFont(&LogFont);
LogFont.lfWeight = FW_NORMAL;
NewFont.CreateFontIndirect(&LogFont);
I found this code in quite a few examples in forums, but the call to GetLogFont causes an assertion failure:
_AFXWIN_INLINE int CFont::GetLogFont(LOGFONT* pLogFont)
{ ASSERT(m_hObject != NULL);
return ::GetObject(m_hObject, sizeof(LOGFONT), pLogFont); }
I can't even figure out what the m_hObject is supposed to contain, let alone why it's NULL. Anyone have a clue?
Thanks a lot,
ren
|
|
|
|
|
The GetFont() call is returning NULL. This will normally only work if a call to SetFont() or WM_SETFONT message has already been done/sent to the window in question.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
How can I send an EMail from an MFC Project without DOC/VIEW Architecture and without MAPI messanging?
|
|
|
|
|
SMTP is an option. there is code here that will help.
-c
Cheap oil. It's worth it!
|
|
|
|
|
If i can't use CString in my non-mfc app then how do i use the AllocSysString?
Thanks
|
|
|
|
|
SysAllocString (and SysFreeString to free resources)
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Hi!
Is there a way to know if a mail program is present on a system and correctly installed. Because when I use the Windows MAPI functions, my program fails if there is no program set.
I'm programming in C-Windows.
Thks in advance!
Appstmd
|
|
|
|
|
You can check the following registry key to see if any profiles exist:
Win9X/ME:
Software\Microsoft\Windows Messaging Subsystem\Profiles
WinNT:
Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles
|
|
|
|
|
How can I write text and draw lines in a MS Word Application from an MFC Project without DOC/VIEW Architecture???
|
|
|
|
|
You might want to look at COM Automation. It's a lot of work to get your head round at first, but it'll do what you need.
A starting point would be in MSDN, under:
Platform SDK-->COM and ActiveX Object Servies-->Automation
HTH,
Pete
|
|
|
|
|
Are there any specific precautions to using A2W? I am using it in a small piece of code that I have written and I have noticed that at times it appears that I have memory problems.
Any specific things that I need to watch for?
|
|
|
|
|
Acutally sorry I had forgotten to use SysAllocString!
thanks
|
|
|
|
|
A2W allocates memory on the stack, so it may be a problem if you convert very large strings.
SysAllocString allocates memory for BSTR string, not w strings, although the code sees them as equivalent. The difference is that a BSTR has 4 bytes preceding the address of the string that tells the length (in bytes) of the string.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
As michel wrote, it allocates memory on the stack. But, if you use VC++ 7.0, you can use CA2W(), it allocates memory on the heap, if needed, but otherwise it works just like A2W().
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi,
I would like to create a script in C++ for introduce some datas into a executale.
For example : senddata /p test /r test1.
I create a little sample and after I execute my script, the prompt message is closed and I can't see the result.
My sample:
int main(int argc, char* argv[])
{
printf("Hello World!\n");
char *p;
int i;
int iErr;
for (i=1; i
|
|
|
|