将 Windows 服务与交互式窗口 (HWND) 连接的好方法是什么?
我有两项 Windows 技术,我想将它们结合起来:一个 TSP(TAPI 服务提供程序)和一个围绕某些硬件的 API。 API 同步接受请求,但通过向传递的 HWND 发送消息来异步返回成功/失败/状态结果。
据我了解,问题在于,由于 TSP 作为 Windows 服务运行,因此其执行上下文无法访问大多数交互式 Windows 函数。因此,尽管我很想将两者直接链接在一起,但我不能 - 据我所知,TSP 没有(而且确实不能)有一个 HWND发送消息的 API。 :-(
对于像我这样一次只在服务/交互线一侧编写过 Windows 东西的人来说,所有这些都有点令人头疼。但是 Windows 就是这样,必须有当然,有几种合理的方法
可以让我尝试将这两件事联系起来?
I have two pieces of Windows technology which I'd like to plumb together: a TSP (a TAPI service provider) and an API wrapped around some hardware. The API accepts requests synchronously but returns success/fail/status result asynchronously by sending messages to a passed-down HWND.
As I understand it, the problem is that because a TSP runs as a Windows service, its execution context doesn't have access to most interactive Windows functions. So, much as I'd like to directly link the two together, I can't - as far as I can tell, the TSP doesn't (and indeed couldn't) have an HWND for the API to send messages to. :-(
For someone like me who has only ever programmed Windows stuff on one side of the service/interactive line at a time, all of this is a bit of a head-scratcher. But Windows being the way it is, there must be several sensible ways of getting messages across this line, surely?
How would you advise me to try to hook up these two things? Thanks! :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
服务可以创建一个“消息窗口”(父窗口为 HWND_MESSAGE)并运行消息泵。消息窗口没有 UI,因此不与桌面交互。
A service can create a "message window" (a window whos parent is HWND_MESSAGE) and run a message pump. A message window has no UI and therefore doesn't interact with the desktop.
我建议使用 MSMQ 在两个不同的应用程序之间传递消息。我可能有点麻烦,但它会起作用。
I would suggest using MSMQ to pass messages between the two different applications. I can be a little cumbersome but it would work.
您的服务可以在全局对象命名空间中创建一个命名文件映射对象,然后您的交互式程序可以打开该文件映射。然后您可以通过共享内存进行通信。
Your service could create a named file mapping object in the
Global
object namespace, and then your interactive program could then open that file mapping. You could then communicate via shared memory.