Re: Interprocess communication using message queue

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>
>
.



Relevant Pages

  • Re: SetupDiGetDeviceInterfaceDetail fails???
    ... ErrCode = GetLastError(); ... rc = rcErr; ... goto CleanUp; ... > DWORD ert2t=GetLastError; ...
    (microsoft.public.development.device.drivers)
  • Re: Access Denied etc. - appears to be Server 2003 SP1 problem
    ... > If you run this without a command line, it will display the SCM's ACL. ... > DWORD dwreferenceddomain = sizeof; ... > // Return text that goes with GetLastError() ... > DWORD dwError, dwRes; ...
    (microsoft.public.sqlserver.clustering)
  • Processliste anzeigen ... ( Fehler : Zugriff verweigert )
    ... in Funktion "GetProcessModule" ist hModuleSnap immer -1. ... GetLastError() lifert 5 - Zugriff verweigert. ... BOOL GetProcessModule (DWORD dwPID, DWORD dwModuleID, ...
    (microsoft.public.de.vc)
  • Re: Help with finding devices
    ... I'm unsure as to how to convert the ... DWORD from GetLastError to a human readable string that I can output in ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Frage zu DWORD
    ... Objekt und noch ein zusätzliches Flag setzen. ... DWORD in LowWord und HiWord aufzuteilen und ins eine den Pointer zu ... in neueren Versionen wurde dieses DWORD durch einen ... Zeiger zum Flag extern dazu. ...
    (microsoft.public.de.vc)