>> A console creating a hidden window in proc is not the equivalent of a
> service.
Of course it is not. However, a process/window running in the background
waiting for a call is similar to a service.
******
Well, not quite. A service can be running at a different privilege level
and with a different loging ID than the client program, so there are some
significant differences.
****
> You have to update the app to use the service interface, why not just
> require
> they register for notifications?
I’d love to have a simple interface conssisting of WritePacket(),
OpenDev(), CloseDev() - requiring registration for both interface and
handle then writing the correct disconnect/reconnect actions inside
WndProc() is too much to ask from the App developper.
I’ve written a functioning app and I give it away but I dislike it.
*****
I didn’t realize in 2012 that people still cared about “WndProc”,
programming to the native Win32 API for GUI apps. Seems horribly quaint.
Modern native code should be written in MFC, because the native API is
about as much fun as writing in assembler.
Note that if you bundle all these operations into a DLL, the app
programmer should have a simple interface. I consider it a design error
to think about a direct
CreateFile/ReadFile…WriteFile…DeviceIoControl/CloseHandle as the only
acceptable form of interface to a device; it warps your design into being
“simple” when this may be inappropriate; your *interface* to the app
should be simple, but that does not suggest that the interface always be
written at the lowest level.
******
> Or better yet, your dll can create a hidden
> window and register for notifications as easily as the service. There is
> nothing
> wrong with a hidden window
This is what I first thought of. However, my driver allow up to 16
applications to open a handle to it. This may cause 16 instences of this
DLL, each with it’s own disconnect/reconnect mechanism or forcing a
singleton DLL (I don’t see how). Well, a Service is inherently a singleton
and it can interact with both driver and applications.
Needless to say that I will have to write an interface DLL as you
mentioned, that will handle the interface with the service (Via named
pipe, I presume) that every app will have to load.
I see this service as part of the driver so it is assumed that the
installer of the driver instals and starts this service.
****
Seems an odd limitation. Why 16? But what’s this got to do with a DLL?
I don’t even see why there is a concept of a “singleton DLL”. I’m not
even sure that that means!
Named pipes have one advantage over sockets: named pipes can have security
ACLs attached, thus limiting who can connect. If you implement using
sockets, you have to provide your own security mechanisms. Note that if
you use named pipes or sockets, anyone on the network can access the
pipe/port. I think (but am not certain) there is a way to set an ACL to
limit connections to the currently-logged-in local user (someone who is an
expert in ACLs can verify or refute this idea). Or, if you want network
users to have access remotely, that’s fine, too. If you use a named pipe,
you won’t be accessible from machines outside your domain, which may be a
Good Thing or a Bad Thing depending on your goals.
Several notes: DLL code is common to all instances of the DLL (in
general…you can force weird exceptions), so the memory footprint is
smaller than 16x the memory footprint of one DLL. The unshared data
segment(s) are private, but usually there is only one, and usually it is
small, so the private space rarely exceeds one page (not counting any
dynamic allocation the DLL might do). But you have to think of this in
terms of REAL machines, not PDP-11s; 16 instances of n pages, for small
values of n, such as 1, is a meaninglessly small piece of a 2GB…4GB…16GB
physical space, and an irrelevant amount of a 2GB virtual address space.
So don’t try to optimize a nonexistent problem by imposing silly
constraints such as “code size” or “memory footprint”. Until your DLL
starts to be a megabyte or so in size, it is an irrelevant consideration.
Do the arithmetic; don’t believe what you were taught (I find that many
people today have learned from people [or books written by people] who
learned to program on the PDP-11, and therefore have inherited all the
irrelevant habits that were critical for survival when you had 64K bytes
of address space).
*****
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer