all groups > dotnet myservices > february 2005 >
You're in the

dotnet myservices

group:

How do I get hWnd in a .NET service with no UI?



How do I get hWnd in a .NET service with no UI? Dave Hall
2/16/2005 1:54:34 PM
dotnet myservices: Sorry for the cross post. I discovered hhis newsgroup after my original
posting in microsoft.public.dotnet.framework newsgroup and thought it fit
better here.

I have a 3rd party library that requires a non zero hWnd parameter as a
parameter to one of it's functions. I need to ue this library in a Windows
Service with no UI. What .NET class should I use to create a simple
invisible window so I can pass it's hWnd to the 3rd party API? In the .NET
Compact Framework, I would use an instance of the the MessageWindow class,
but that class is not available except in the CF version. Do I have to call
the Win32 APIs directly to create a hidden window in a service? Has anyone
already wrapped this functionality and published it? Any suggestions?

Thanks,
Dave

Re: How do I get hWnd in a .NET service with no UI? Lee Gillie
2/21/2005 9:42:29 PM
[quoted text, click to view]

I think you could make a form, and set its visibility to False. As long
as you don't stall for input, as a messagebox would, it should not hang.
Don't forget, if you are starting as a console app (as services
typically should be) you are going to ALSO need a message pump. Careful
about not doing other processing on the pump's thread that will stall
message delivery. I would use a dedicated thread for this. Myself I
would simply call Win32 API to create the invisible window. I have made
services in VB6 in this way. Also, don't forget to send messages to
close your window, and be sure to process them via the pump when you
want the service to exit. I think you could use the pump built into
application.

AddThis Social Bookmark Button