Re: Pipes on Wince (I have them), and device auto-loading.



Sorry for the delay.

Paul G. Tobey [eMVP] wrote:
You could look at the source code for the Telnet server in Windows CE. It
uses an external service/driver to which it sets SetStdioPathW() for the
appropriate paths for each child process. That driver then has a means of
communicating back with the application so that the output of some program
that you run via Telnet can be sent over the network to the Telnet client
who ordered the run. What happens when it does a run is this:


[snip GetStdioPath/SetStdioPath example]

I already knew how to use GetStdioPath/SetStdioPath, as can be
seen on the code I posted... That was not what I was looking for.

So, replying to myself, for the archives:


I'm using ActivateDevice to load the driver. Since I want to hide
the device nature of the pipe from the user, and I want to reuse
closed pipe devices, I don't pass the HANDLE returned by
ActivateDevice to the pipe creator (the CreatePipe caller). I would
like to somehow have the device auto deactivate when the last
file handle to it is closed.

Currently, I'm keeping a device internal reference count, and when
it reaches 0, I post a Windows message to an internal window that
is implemented in PipeLib. In PipeLib there is a thread that waits
for these messages and DeactivateDevice's the device accordingly.

This deactivating only works if the child closes all the pipes
handles before the parent. If the parent dies, the device will leak.

The real solution I'm after is auto device unloading. Any ideas?


WinCE stores a handle to the driver as a dword in the registry, that
one can use from the address space of Device.exe (the driver's
address space). I use that for calling DeactivateDevice.

B.t.w: I'll release the Pipe driver and lib as BSD or similar once
these issues are fixed.

No proper release yet, but I've uploaded it at cegcc's svn here:
http://cegcc.svn.sourceforge.net/viewvc/cegcc/trunk/cegcc/tools/

The rshd server in that dir uses PipeLib.

Here's a snippet of 'getting at the handle' for the casual googler:

static HANDLE
GetDeviceHandle (PipeDeviceContext* pDeviceContext)
{
HKEY hActive;
DWORD Type;
HANDLE hDev = INVALID_HANDLE_VALUE;

DWORD status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, pDeviceContext-
ActivePath,
0, 0, &hActive);
if (status != ERROR_SUCCESS)
return INVALID_HANDLE_VALUE;

DWORD Len = sizeof(hDev);
status = RegQueryValueEx (hActive, DEVLOAD_HANDLE_VALNAME, NULL,
&Type,
(PUCHAR)&hDev, &Len);
if (status != ERROR_SUCCESS)
{
/* weird */
}

RegCloseKey (hActive);

return hDev;
}

Cheers,
Pedro Alves

.



Relevant Pages