Prior to Windows CE 5.0, you could only have up to 10 instances of a driver with the same prefix, like COM. So you could only CreateFile on COM0: through COM9:. Starting with Windows CE 5.0, there is support for BUS mount points ($bus\USBFN_1_0) and device mount points ($device\COM8) which can be used to open a handle to a driver.
Platform Builder Help documents these in Device File Names, which isn’t so easy to find.
I created a little test to show how to use the different names:
void OpenADriver( TCHAR *Driver )
{
HANDLE hDriver;
RETAILMSG( 1, (TEXT("Opening %s\n" ), Driver));
hDriver = CreateFile( Driver,
GENERIC_READ,
0,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0 );
if( hDriver != INVALID_HANDLE_VALUE )
RETAILMSG( 1, (TEXT("%s opened\n" ), Driver));
else
RETAILMSG( 1, (TEXT("%s failed to open %d\n" ), Driver, GetLastError()));
CloseHandle( hDriver );
}
Then call OpenADriver in different ways:
OpenADriver( TEXT("$device\\COM1") );
OpenADriver( TEXT("\\$device\\COM1") );
OpenADriver( TEXT("COM1:") );
// Assuming that you have a COM11 to test against
OpenADriver( TEXT("$device\\COM11") );
OpenADriver( TEXT("\\$device\\COM11") );
OpenADriver( TEXT("COM11:") ); // This one should fail even if you have a COM11
If you take a look at my post about enumerating device drivers, you will see that you can enumerate and get the Device Name and Bus Name from code.
Windows CE: Listing Running Drivers shows how to list the loaded device drivers.
Copyright © 2008 – Bruce Eitman
All Rights Reserved