views:

32

answers:

2

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! :-)

+1  A: 

I would suggest using MSMQ to pass messages between the two different applications. I can be a little cumbersome but it would work.

Climber104
A: 

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.

Tergiver
So, I'd call RegisterClass(), then
Nick Pelling
@Nick: Yes, you need to RegisterClass (to register your WndProc) and CreateWindow just as in a UI app, as well as GetMessage/DispatchMessage in a loop to pump messages. The usual call that would be skipped is ShowWindow/UpdateWindow since there is no visual to show.
Tergiver
OK, thanks Tergiver, I'll give it a go! :-)
Nick Pelling