HI Jason, I have the following in my stdafx.h file:
// string message allocator for posting messages between windows...
static char* AllocBuffer(char *strMsg)
{
int nLen = strlen(strMsg)+1;//strMsg.GetLength();
char *pBuffer = new char[nLen+1];strcpy(pBuffer,(const char*)strMsg);
ASSERT(pBuffer != NULL); return pBuffer; }
and use it within my postmesage function as: char Tmp[40]; strcpy(Tmp,"TEST"); ::PostMessage(m_DialogHWND,WM_MESSAGEHERE,0,(LPARAM) AllocBuffer(Tmp));
and within my posted message I delete it:
LRESULT CTelServerDlg::OnSendUpdatedStation(WPARAM wParam, LPARAM lParam)
{
char* pString = reinterpret_cast<char*>(lParam);
PER_HANDLE_DATA *TmpHandleData=PerHandleData;
delete [] pString;
return 0;
}As I am using 2 processors, and having 4 threads in my IOCP. If for example 4 threads do a Postmessages with he same message,(for example the above message). When the system comes to execute the function 4 times, does it wait until one is finished before doing the next one? If not, suppose I am better doing a EnterCriticalSection(..) and LeaveCriticalSection(..) withn the routine?
Thanks for the help Neil
----- Original Message ----- From: "Jason Teagle" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, April 30, 2005 10:23 AM
Subject: RE: [msvc] Posting a message
I have a couple of threads created with socket IOCP. Is it safe to post amessagewithin the thread? I occasionally got an error , which I think codewarriorpoint it to a::SendMessage(..) command within my thread. I changed the ::SendMessage(..)to::PostMessage(..) and seams to be fine. Can it be that SendMessage() waitsuntilthe Send routine is complete, and Post message posts the message in returnsfirst
immediately? I have a handle to the main dialog box in which I use in theparameter of PostMessage.
Yes, SendMessage() waits for a response from the message handler, whereas PostMessage returns immediately. Just be careful with any data passed through PostMessage() as pointers, though, since it needs to still exist even when PostMessage() returns - otherwise when the handler comes to process it, the pointer would point to no-man's land and you'd be in trouble.
-- Jason Teagle [EMAIL PROTECTED]
_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
_______________________________________________ msvc mailing list [email protected] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
