IPC mechanism introduction on Windows Mobile

Introduction

In this article I want to introduct two IPC mechanisms when developping windows mobile applications.

 

Background

I implemented a windows mobile application to levelage the scanner API on Nomad device. Whereas, Nomad device will launch another light weight application named 'scanner agent ' to trigger the scanner. The problem I'm encountering is that all the control logic resistent in my mobile application and I have to adapt 'scan agent' to communicate with my mobile application. Subsquently, I decide to utilize MSMQ in both .NET application to accomplish it.

Once I implemented, I noticed that there is approximatically one second delay to trigger the scanner in the light weight application. Given that, I added the diagnostics statement(StopWath) in the adapted scanner agent. After all, I got the conclusion that it takes about 1 second to load the .NET application on the windows mobile without executing any code in the adapted scanner agent.

 

Solution

 So, I had to begin to porting scanner agent from c# application to a c++ application. I tested the c++ version sanner agent, it worked like a charm and there no appreciable delay any more.  But there is still a drawback for this solution that scan agent must depend on MSMQ whereas mobile device doesn't have it installed as default componment. Thurmore, you have to run some relevant command to utlize MSMQ prior to leverage it and it was said that much more power would be costed once we enable the MSMQ.

Given that, I decided to try to find an alternative approach to overcome those known shortcoming in my solution. Fortunately, I had heared about Message Queue Point to Point on windows mobile. So, I went through some sample codes from MSDN regarding windows mobile power management to check whether it's suit for my situation. After about 1 hour research and quick try, it's proved that the Message Queue Point to Point is the IPC mechanism on windows mobile  I wanted.

Here are the pros of Message Queue Point to Point I realized so far,

1.Light weight with comparision to MSMQ

2.Low programming level  required.

3.Both Net and C++ utlizing SDK API, so less learning cost

4.It's bidirectional via creating tow queues(one for input and the other for output)

After refine my solution by having Message Queue Point to Point involved, I got a perfect solution for my situation.

 

Impendiment

I got error code ERROR_INVALID_HANDLE when invoking ReadMsgQueue and WriteMsgQueue on the handle which I had received or wrote some data from.

Here is the comments from MSDN developer community regarding this issue,

Also note that once a call has been made on the broken queue, then queue handle becomes worthless for use.  For example if you write on a queue with no listener the call will fail and GetLastError will return ERROR_INVALID_HANDLE.  If you subsequently add a listener to the queue, calls to write to the queue with the original handle will continue to fail.  You must close the handle and reopen the queue to be able to write without failure.  The same behavior exists for both WriteMsgQueue and ReadMsgQueue.       

Given that, I recreated inbound/outbound queue handle after receiving/sending message  from/to relevant queue. It works and I do appreciate the help from the developer community.

 

Conclusion

 If you ONLY want the IPC ability for your mobile solution, Message Queue Point to Point should be your choose. Otherwise, if you want the persistence queue supported for you  solution, MSMQ is probally your choice but keep in mind that you have to iniatizing it prior to utlizing it. Event for cumminication between C++ application and C# application, they're leverage differnt programming API. Especially for C++ application, please ensure that you know how to programming COM based application.

 

Appendix,

Just to clarify some confusion if someone comes across this thread at a later date via a search engine etc.

Windows Mobile supports two different message queue technologies:

Each is designed for a slightly different use case.

The Compact Framework provides no wrapper for point-to-point message queues, but it does provide a wrapper for the MSMQ framework.

 

History

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值