I'm using CreateFile to open a connection to my USB hardware. If I have two (or more) hardwares connected to the PC I would like to prevent several instances (different PIDs) of my PC-application to connect to the very same hardware.
I thought this was accomplished by running CreateFile with dwShareMode = 0. For some reason this doesn't work. Several different instances of the PC-application will get a valid handle when running CreateFile towards the same USB-device.
hDev = CreateFile(
"\\\\?\\usb#vid_0442&pid_0891&mi_01#6&2ea0fbc8&0&0001#{ff646f80-8def-11d2-9449-00105a075f6b}"
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL
);
If possible I would like to make this work as I want without changing the driver since that will invoke driver certificate signing, yadayada...
What have I missed?
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx