Groups | Blog | Home
all groups > dotnet interop > december 2003 >

dotnet interop : Windows service and messages


Brent Horine
12/31/2003 9:18:25 AM
I need to work with an unmanaged DLL for a socket based wireless
communication API. I'm wrapping it with a combination of unmanaged and
managed C++ calls and running everything in a .NET Windows Service. When it
receives a message over the network, it posts a WM_SOCKET_STATUS message
that I have to catch and handle. The initialization of the library requires
the application's instance handle and the window within the client
application to send notification of incoming data to. Their example code
uses AfxGetInstanceHandle() and GetSafeHwnd() for these values.

How do I do this (AfxGetInstanceHanlde and GetSafeHwnd) in a .NET Windows
Service? Whether an interactive user is logged in or not. This will run on
a remote server and it will be rare that someone will be logged on.

Thank you,

Brent

Bart Jacobs
12/31/2003 5:24:33 PM
Brent,

So the code that posts the message is in the same process as the code
that gets the message? That is an awkward design. It would have been
better if the DLL that posts the message simply called a callback
function instead.

Having said this, given the current awkwardly designed DLL, the solution
clearly involves creating a window in your service process. Have you
tried a call to the CreateWindow API? Does it succeed?

Good luck!

Bart Jacobs
Mattias Sjögren
1/1/2004 5:20:03 PM
Brent,

[quoted text, click to view]

AfxGetInstanceHandle => Marshal.GetHINSTANCE() on the Module your
code is in.
GetSafeHwnd => the Handle property of a Windows Forms form or control.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button