Re: Interprocess communication using message queue
- From: "Khris" <Khris@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Apr 2005 07:56:09 -0700
Here is my Code Snippet.
In the first process:
MSGQUEUEOPTIONS msgopts, msgopts1;
HANDLE hq, hq1;
DWORD size, flag;
msgopts.dwSize = sizeof(MSGQUEUEOPTIONS);
msgopts.dwFlags = MSGQUEUE_ALLOW_BROKEN;
msgopts.dwMaxMessages = 10;
msgopts.cbMaxMessage = 10;
msgopts.bReadAccess = TRUE;
hq = CreateMsgQueue(TEXT("DLLTEST11"), &msgopts);
DWORD err = GetLastError();
msgopts1.dwSize = sizeof(MSGQUEUEOPTIONS);
msgopts1.dwFlags = MSGQUEUE_ALLOW_BROKEN;
msgopts1.dwMaxMessages = 10;
msgopts1.cbMaxMessage = 10;
msgopts1.bReadAccess = TRUE;
hq1 = CreateMsgQueue(TEXT("DLLTEST11"), &msgopts1);
DWORD err1 = GetLastError();
if(WriteMsgQueue(hq, &lpBuffer, sizeof(LPVOID), INFINITE, 0x00)==TRUE)
{
MessageBox(TEXT("SUCCESS"), TEXT("AAAAA"), NULL);
}
if(ReadMsgQueue(hq1, &lpBuffer1, sizeof(LPVOID), &size, 2000, &flag)== TRUE)
{
MessageBox((LPCTSTR) lpBuffer1, TEXT("YAHOO"), NULL);
}
else
{
DWORD err = GetLastError();
MessageBox(TEXT("FAIL"), TEXT("FAIL"), 0);
}
CloseMsgQueue(hq);
CloseMsgQueue(hq1);
And in my Second process I try to access this queue again to read the data,
MSGQUEUEOPTIONS msgopts1;
HANDLE hq1;
DWORD size, flag;
msgopts1.dwSize = sizeof(MSGQUEUEOPTIONS);
msgopts1.dwFlags = MSGQUEUE_ALLOW_BROKEN;
msgopts1.dwMaxMessages = 0;
msgopts1.cbMaxMessage = 10;
msgopts1.bReadAccess = TRUE;
hq1 = CreateMsgQueue(TEXT("DLLTEST2"), &msgopts1);
DWORD err1 = GetLastError();
if(ReadMsgQueue(hq1, &lpBuffer1, sizeof(LPVOID), &size, 2000, &flag)== TRUE)
{
MessageBox(NULL, (LPCTSTR) lpBuffer1, TEXT("YAHOO"), NULL);
}
else
{
DWORD err = GetLastError();
MessageBox(NULL, TEXT("FAIL"), TEXT("FAIL"), 0);
}
CloseMsgQueue(hq1);
Thanks
Khris
"Alex Feinman [MVP]" wrote:
> calling Create twice is correct. Could you post some code snippets to show
> how you read and write?
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Khris" <Khris@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:2286BE73-C6E5-4357-AFB0-102B49D7530D@xxxxxxxxxxxxxxxx
> > Hello,
> >
> > I am developing an application using EVC++ and I am using message queue
> > for interprocess communication. I am able to read the data that I write
> > into
> > the queue using ReadMsgQueue in the same process but when I try to read
> > data
> > that is there in the queue in another process it fails. Is there something
> > that I am missing. The error I get is 1460, Error_TIMEOUT.
> >
> > I have createMsgQueue twice in each process, to get the read handle and
> > the write handle respectively. Do I have to use any other API's like
> > OpenMsgQueue too.
> >
> > Thanks in advance
> > Khris
>
>
.
- Follow-Ups:
- Re: Interprocess communication using message queue
- From: Alex Feinman [MVP]
- Re: Interprocess communication using message queue
- References:
- Interprocess communication using message queue
- From: Khris
- Re: Interprocess communication using message queue
- From: Alex Feinman [MVP]
- Interprocess communication using message queue
- Prev by Date: RE: Shortcut Menu Extensions
- Next by Date: Re: Crashes in Debug (random) but not release
- Previous by thread: Re: Interprocess communication using message queue
- Next by thread: Re: Interprocess communication using message queue
- Index(es):
Relevant Pages
|