I want to do interprocess communication between a c++ app and a vb.net app on T30. I activated the Option Message Queuing (MSMQ) in Catalog Items View of Image. But running the application it runs to an exeption: “Message Queue service is not available.” in vb.net app. Here are the Code snipets:
'Init
Dim msg As New System.Messaging.MessageQueue(".\DKMSG", True)
Try
'Receive Message.
Dim myMessage As System.Messaging.Message = msg.Receive()
Dim sMessage As String = CType(myMessage.Body, String)
Catch ex As Exeption
End Try
I have tested native code message queue functionality, it is working. Please download the sample code from here : MsgQueueTest and do the test on your side and let us know the feedback.
If it is working then Could you please convert client native code to C# or vb.net.
Please let us know if you have any other questions.
There is written: “Note Message queuing in the kernel is not related to the Message Queuing (MSMQ) implementation for Windows CE. For information about MSMQ, see Message Queuing.”
My next Question is: How to implement Message Queue Point-to-Point in c# or vb.net?
'Deklaration
Private Structure MSGQUEUEOPTIONS
Dim dwSize As Integer
Dim dwFlags As Integer
Dim dwMaxMessages As Integer
Dim cbMaxMessage As Integer
Dim bReadAccess As Boolean
End Structure
'Imports
<DllImport("coredll.dll")> Private Shared Function CreateMsgQueue(name As String, ByRef options As MSGQUEUEOPTIONS) As IntPtr
End Function
<DllImport("coredll.dll")> Private Shared Function ReadMsgQueue(hMsgQ As IntPtr, lpBuffer() As Byte, cbBufSize As UInt32, ByRef lpNumRead As UInt32, dwTimeout As Integer, ByRef pdwFlags As UInt32) As Boolean
End Function
'Coding, do it in a thread.
Dim opt As New MSGQUEUEOPTIONS
opt.dwSize = 20 'Size of MSGQUEUEOPTIONS
opt.dwFlags = 2 '1 = MSGQUEUE_NOPRECOMMIT; 2 = MSGQUEUE_ALLOW_BROKEN
opt.dwMaxMessages = 1
opt.cbMaxMessage = 100
opt.bReadAccess = True
Dim hwd As IntPtr = CreateMsgQueue("DKMSG", opt)
While Not locEnd
Try
Dim szMsg(99) As Byte
Dim dwNR As Integer = 0
Dim dwFlags As Integer = 0
Dim br As Boolean = ReadMsgQueue(hwd, szMsg, 100, dwNR, 1000, dwFlags)
If Not br Then
'Something was wrong or no message arrived in the timeout
ShowTextFromMsg("Error at Queue!")
Else
Dim sMessage As String = System.Text.Encoding.Unicode.GetString(szMsg, 0, dwNR)
ShowTextFromMsg(locMessage)
End If
Catch ex As Exception
End Try
End While