|
SendMessage() sends a message to the target window synchronously - i.e. it waits for the message to be processed before returning. Consequently, it is inherently dangerous to use SendMessage() to send messages between threads. It blocks the sending thread until the message is processed, and so if the target thread then does something that requires a response from the first thread, deadlock will occur. It is possible to design your application in such a way to ensure this will not happen, but it is generally not the preferred option. Generally you should use PostMessage() or PostThreadMessage() to communicate betweeen UI threads.
Dave
|
|
|
|
|
The reason I ask is because I was using PostMessage but the thread would exit before the lParam value (CString) could be read by the main app.. I assumed that if I used SendMessage the UI thread would wait until the main app read the message..
|
|
|
|
|
You should create the CString (or whatever data structure) on the heap instead:
CString* pStrResponse = new CString( "My string" );
if ( !::PostThreadMessage( dwMainThread, myResponseThreadMessage, wParam, reinterpret_cast<LPARAM>( pStrResponse ) ) )
delete pStrResponse; // Only delete it if the post failed
Then in the main thread
LRESULT CMyApp::OnThreadResponse(WPARAM wParam, LPARAM lParam)
{
CString* pStr = NULL;
try
{
pStr = reinterpret_cast<CString*>( lParam );
// Do something with it
}
catch ( ... )
{
ASSERT( FALSE );
}
delete pStr; // Make sure we delete this even if an exception occurs
}
Dave
|
|
|
|
|
Dave, u da man!
Tnx..
|
|
|
|
|
take a look at SendMessageTimeout()
From MSDN:
SendMessageTimeout
The SendMessageTimeout function sends the specified message to a window or windows. The function calls the window procedure for the specified window and, if the specified window belongs to a different thread, does not return until the window procedure has processed the message or the specified time-out period has elapsed. If the window receiving the message belongs to the same queue as the current thread, the window procedure is called directly — the time-out value is ignored.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Hello All,
Have a question about declaring an abstract base class in a .dll. Basically, we have something like this, in a header file of a regular win32 .dll":
class DLL_API IMyClass
{
public
virtual int DoSomething()=0;
}
which resolves to something like dllimport in the client code. If the client of this .dll is another .dll, I get an LNK2001, an unresolved external for a default constructor. Why would I need a constructor, you can't use new on an interface class.
Anyway, what's the appropriate way to do something like this? Make an abstract base class available to client code, while hiding the implementation. What does the dllimport attribute really mean for a type that is abstract, anyway? Is it even relavent? Taking off the DLL_API macro thingy from the class gets rid of the LNK error.
Thanks,
aaron
|
|
|
|
|
If using pure abstract classes, dllimport makes no sense at all, and you can safely omit it. As for the particular problem you were experiencing, probably the client DLL is "seeing" the DLL which holds IMyClass with dllexport , as DLL_API resolves to import/export depending on the _DLL macro (I guess). The default ctor, as you correctly point out, is never explicity called, but it does get called for classes derived from IMyClass .
Going the way of exporting classes through an abstract base, omit import/export qualifiers for IMyClass and declare a couple of functions like this:
IMyClass * DLL_API CreateMyClass();
DLL_API DestroyMyClass(IMyClass *); You might be tempted to omit DestroyMyClass and use delete instead: this is a bad idea, since you're likely to run into incompatibility problems between the versions of the C run-time library used by the various components of the program.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
OK, thanks, that makes sense. In this instance, most of the stuffin the .dll is created through a sort of factory, so most of the interfaces the client actually sees, he didn't get by calling new himself.
|
|
|
|
|
How does this work? Even for other Icons on the desktop ,what steps are involved for creating a customized MyAppIcon>Right Click>Properties> MyPopUpMenu ??
I have tried looking around, no luck thanks
Joe
"You can't throw yourself a parade every time you win, and you can't bury yourselves when you lose."-Levon Kirkland Philadelphia Eagles
|
|
|
|
|
Check out the msdn article # Q236312 -- I've used something similar to what's in the Driller sample to disable the rt-click menu. I think this article also shows you how to override it or create your own.
Chris
"No one goes to hell because of their sin, but because of rejecting God's method of salvation: His Son's life for yours..."
"It does not take a majority to prevail ... but rather an irate, tireless minority, keen on setting brushfires of freedom in the minds of men." --Samuel Adams
|
|
|
|
|
Thanks, I'll check it out
|
|
|
|
|
If any one else had trouble with the search results for that article number like I did, here is the direct link
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/browser/driller/default.asp
|
|
|
|
|
Hi, I want to receive data from multiple TCP clients, but I don't find information about.
Can me anyone help me with a link to usefull info...
Thank in advance...
Lo mejor de la vida, es vivirla!!!
|
|
|
|
|
There are many options to accomplish what you want. As a primary source for info on programming with Winsock, Warren Young's Winsock Programmer's FAQ[^] is an excellent site.
Also, Oz Ben Eliezer provides a concrete example of multi-client app in his article Writing scalable server applications using IOCP[^]. You might want to take a look at the code and extract some ideas from it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Gracias, Joaquín, por el dato...
Suerte!!
|
|
|
|
|
I just got Visual C++ 6.0 and would like to be able to Show Line Numbers, but for the life of me I can't find where to turn that option on. Is it even possible to do so? I would hope it is. Any help with this would be great, thanks.
Ehren
ehrengh@yahoo.com
|
|
|
|
|
The only way that I know of to display line numbers is to click on a line, then look in the lower-right panel of the status bar, which displays the line number that the cursor is on. To jump to a specific line, press Alt-G and enter the line number...
Chris
"No one goes to hell because of their sin, but because of rejecting God's method of salvation: His Son's life for yours..."
"It does not take a majority to prevail ... but rather an irate, tireless minority, keen on setting brushfires of freedom in the minds of men." --Samuel Adams
|
|
|
|
|
Hi,
How to add an icon to the task tray where the clock shows.
Thanks.
Laura
|
|
|
|
|
here
or here
or here
Is it so hard to search the CP.com site?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Sometimes is can be, for a newcomer or visitor. When I was new, it took me a short while to properly navigate the whole site...
... as I see it, it is a compliment to people who make CP what it is... a website with a LOT of content!
: Dean 'Karnatos' Michaud
|
|
|
|
|
I'm sure there is an article in CP that describe it,but I can't remember in which part.Search this site with "systray" keyword I guess.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I am looking for an example of how to make a toolbar for the desktop, similar to the one from MS Office. I'd like for it to be dockable to the sides of the desktop if at all possible. I'm not asking someone to write me one, just wondering if there's already an article that you know of that covers this already.
: Dean 'Karnatos' Michaud
|
|
|
|
|
|
I building a blocking TCP class library which I will use in my server soon.
But do I need to, or is it good to check if the SOCKET in the CTcpListener class is ok (not INVALID_SOCKET or SOCKET_ERROR) in Create(), Bind() and Listen()???
I mean it's an listening socket, is it necessary!?
In my class that connects to a SOCKET (CTcpClient), should I error check the SOCKET in Connect, Send, Create etc. Or is it unimportant?
I need advices!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Sure it is very important to check whether your socket is valid, e.g. bind() could fail if another application is already listening on a port your app wants to listen on.
I'd suggest you to check the return values of all socket functions. And since you're building a wrapper class around the socket functions you could make the wrapper functions return e.g. a bool true, if a function succeeds, and "false" if it doesn't.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|