|
Mike Dimmick wrote:
SendMessage does indeed do a direct call, if and only if the thread calling SendMessage is the same one that created the window. Otherwise, SendMessage adds a message to the window's thread's message queue (which takes priority over posted messages) and blocks until either the windows procedure returns or until it calls ReplyMessage.
Ah ha!!! I didn't know that
In the light of your comment (and the other replies to my question) I'm rethinking the strategy to eliminate the UpdateThread. Alas performance suffers a little but I'll live with that in return for increased robustness.
Rob Manderson
http://www.mindprobes.net
"I killed him dead cuz he was stepping on my turf, cutting me out of my bling the same way my ho cuts cookies, officer"
"Alright then, move along" - Ian Darling, The Lounge, Oct 10 2003
|
|
|
|
|
Rob Manderson wrote:
Ah ha!!! I didn't know that
In that case, I recommend chapter 26 (Window Messaging) of Jeffrey Richter's Programming Applications for Windows, Fourth Edition. Heck, I recommend the whole book.
Chapter 26 goes into great detail about what's available with window messages, how they're processed, and how you can process them. I use window messages for a large part of my interthread synchronisation and communication.
This book should very much be considered the counterpart to Petzold's Programming Windows - Petzold teaches UI, controls and graphics, while Richter teaches threads, processes, jobs, memory, synchronisation, scheduling, DLLs, exception handling, window messages and input.
|
|
|
|
|
If I've read this correctly you are (indirectly) calling SendMessage() from a worker thread to act on a window that lives in the main app thread. If so you are asking for trouble, because it is very easy to get into a deadlock situation. This can happen because the main thread is processing some windows request, and your sendmessage has to wait until tht finishes and these actions beat on each other. It is late here on Oz and this isn't sounding too good.
To do this sort of thing across threads I always use PostMessage(). If the worker thread has to wait until the message has been processed then I use an event which I wait on in the worker thread. The app thread will signal the event when it has done whatever I've requested of it.
Another approach for this specific bit of code might be a publish-subscribe approach, where the worker threads publishes the information to say an STL vector, and the app thread checks this from time to time and pulls stuff which is waiting. But I'm probably heading off the track and off to bed.
Hope I've been of help.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Yup, you and Mike have both been of help, if only to convince me to drop the two thread approach and use the PostMessage mechanism instead
Rob Manderson
http://www.mindprobes.net
"I killed him dead cuz he was stepping on my turf, cutting me out of my bling the same way my ho cuts cookies, officer"
"Alright then, move along" - Ian Darling, The Lounge, Oct 10 2003
|
|
|
|
|
Threads have their place, and are especially usefull when there are some serious background processing requirements. In ED (see sig) I use threads for Find/Repalce in Files, Source Database updates etc. and they make for a much better user experience. However getting your design and implementation 100% correct so you can't get into a deadlock situation can be quite difficult. And of course there may also be synchronization issues. MFC makes multithreading which interacts with GUI components more difficult because CWnd maps aren't accessible across threads.
I wouldn't give up on your multithreading, but maybe it can be simplified down to a single thread. And make sure you never call anything that calls any function that can block, like SendMessage().
As an aside I use a technique similar to what you describe to end threads, however the technique that Peter Hancock uses in "An exception safe OO thread-pool framework" is quite neat. See: http://www.codeproject.com/threads/threadlibrary.asp[^] Peter forces the thread to throw an exception and then shut itself down (or something like that). Worth a look. Also the thread pool itself is very good.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
My bet is that the thread does InsertItem. This calls the wrapper function which calls SendMessage(). This needs to be processed in the UI thread, which is waiting for the thread to terminate. You need to check if its terminated, if not, pump any messages in the queue locally and then check again until the thread terminates correctly.
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Hello everyone,
in my application i have one main toolbar & each button has a toolbar associated with it (Drop-down toolbar). on click of a button int the drop-down toolbar i want that image to come on top on the main toolbar. i dont know how to do this....can anybody help me?
thanx
|
|
|
|
|
Hi !
I'm wondering if it's possible to put a template class in a vector.
Let me explain :
I have a class which is a template, for instance
template <class t="">
class JSObjectList
{
...
};
In my app, I'd like to have a vector of elements of this class, which would look like this (I guess) :
std::vector<jsobjectlist<t> >
If I try to do something like this, the compiler is complaining about many things....so before trying to understand each error, I'd like to know if what I'm trying to do is allowed in C++ !
Thanks !
Jerome
|
|
|
|
|
It's allowed.
std::vector< JSObjectList< int > > However, there are a number of constraints your type will have to satisfy to be usable with vector . An exact list is hard because it depends on what you're trying to do with it - C++ only instantiates the functions you use, so you only need satisfy the constraints of the functions you're using.
At minimum, your template class JSObjectList needs to expose a copy constructor, and an assignment operator.
|
|
|
|
|
Is anyone who knows how to add a button (toolbar) to the Microsoft Outlook Express. I know there are some aplications which add extra buttons to OE. The second question is how to call a function when an email arrvies?
Please help
|
|
|
|
|
When I compile my project, I have a strange error:
Error spawning cl.exe
Creating browse info file...
Error spawning bscmake.exe
CabCal.exe - 1 error(s), 31 warning(s)
I never had this before !! I just changed some lines and now, it gives me this error !!!
Somebody knows what happens here ????
Thanks
|
|
|
|
|
If there is no problem with your code, then try restarting the machine ( i guess you must have done that by now) if still that didnt solve that problem then you need to check out the microsoft side, its a know bug.
The World is getting smaller and so are the people.
|
|
|
|
|
Hum, really strange problem: now that works fine.... and I didn't restart my machine
And I didn't change anything
|
|
|
|
|
Hi!
I have a problem. I will connect to rman with visual c++ 6. the code is
sConnect.Format("%s/%s@%s",sUser,sPW,sDB);
char *pConnect = new char[sConnect.GetLength()+1];
strcpy(pConnect, sConnect);
nError = _spawnlp(_P_WAIT, "rman", "rman", "target",pConnect, NULL);
It works. But now I want to write commands to the rman console but it don't work. My code is
sConfigure.Format("Configure default device type to %s;",sTyp);
char *pConfigure = new char[sConfigure.GetLength()+1];
strcpy(pConfigure, sConfigure);
nError = _spawnlp(_P_WAIT, pConfigure, NULL);
The programm don't wrie the command "configure default device type to disk" in the console.
Can somebody help me how I can write commands in the rman console?
Thx!!!
|
|
|
|
|
Hi, I'd like to build a network scan tool, which can find out active hosts on the network, their IP addresses, TCP ports etc. But I am not sure how to implement the "ping" functionality, should I implement my own "ping" by using RAW Socket or using a pipe to get the output from the system's "ping.exe" and examine the information that returned.
Since I want this program to work in a fast pattern, so it can scan serveral destination -- ip and tcp ports -- simultaneously, but I don't know whether to use multi-process or multi-thread, I am not sure about the main difference between child process and thread.
Any suggestions will be greatly appreciate!
Thank you!
|
|
|
|
|
hi,
for getting printer DC by this way is usual
CPrintDialog pDialog;
pDialog.DoModal();
dc.Attach(pDialog.GetPrinterDC());
there is any other way to getprinter dc with out showing the printdialog. i need to print some content without showing the printdialog. any one help to me.
thanks in advance.
Murali.M
|
|
|
|
|
You should just be able to call
CDC dc
if (AfxGetApp()->CreatePrinterDC(dc))
{
which will use the current printer selected for your application.
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Hello all,
I need help here - there's a pointer corruption somewhere (I guess), and the debugger throws me out with the following call stack:
ntdll.dll! 77f75a58()
abababab()
That's it! Could someone tell me how to debug this and see what's happening and where?
Oh, it also says this in the output window:
HEAP[my.exe]: Heap block at 0181FC40 modified at 0182051C past requested size of 8d4
TIA
|
|
|
|
|
There may be cases where due to wrong programming logic may coz errors in the system dlls... you need to check out ur programm properly first.
The World is getting smaller and so are the people.
|
|
|
|
|
Mr.Prakash wrote:
There may be cases where due to wrong programming logic may coz errors in the system dlls... you need to check out ur programm properly first.
Well, I did spend a lot of time checking it out otherwise I wouldn't be asking for help It's narrowed down to one function, but I need to trace through it to see where exactly things go wrong and I can't do that without a callstack. And if I put a breakpoint in that function just before it is supposed to return an error, if overwrites the memory and I never hit my breakpoint, things just assert.
|
|
|
|
|
Are u using MFC or not,
If you are using MFC then make sure that you have not accidently included any cpp file in ur workspace that belonges to the core MFC. other than this i cant help you, I had similar prob (not exact) my program logic was correct but due to inclution of a core mfc cpp file in my project ( which i did accidently) my software used to fail terribaly.
regards,
The World is getting smaller and so are the people.
|
|
|
|
|
Yes, I am using MFC and I'll check if there are any core MFC files included in the project, there are included in my stdafx.h of course, but I guess you mean if it's actually included and shows up in the Solution tab?
I've narrowed the problem to one function that does in-memory array manipulation, but I have no idea why it fails, it looks innocent enough.
Thanks.
|
|
|
|
|
Yeah is any mfc core file included in ur solution, (workspace)
Like i said i had similar prob, when any core file is included, even the most inocent looking code will through exceptions.
The World is getting smaller and so are the people.
|
|
|
|
|
Nope, just checked and there're no core files directly included in my workspace It's a really strange problem.
|
|
|
|
|
That °%$$! happened to me too once. this problem can happen if you use a pointer ( or a pointer to a pointer ....a.s.o. ) incorrectly, like so:
char* lpstr = (char*)malloc(5 * sizeof(char)), *p;
// ...
while( /* sth */ ) *p++ = *lpstr++;
// ...
strcpy(lpstr, "12345");
// or
free((void*)lpstr);
so check out step-by-step if your variable remains at it's original position.
don't no if this could help you out...
Phil
|
|
|
|