Using platform/Invoke I just succeeded using Win32 APIs, CreateFile and DeviceIoControl from a VB.net UWP in windows 10 desktop to access our custom Cypress FX2 based USB device using our own WDM driver.
Method 1 documented in https://developer.microsoft.com/en-us/windows/iot/Samples/CustomDeviceAccessor
works fine for the desktop too.
Here is a frame grab of the command prompt to make registry settings to grant Access to "AppContainer Processes" to our hardware!
C:\WINDOWS\system32>schtasks /delete /tn DeviceAC /f
ERROR: The system cannot find the file specified.
C:\WINDOWS\system32>schtasks /create /RU SYSTEM /SC ONCE /TN DeviceAC /TR "reg import c:\data\deviceac.reg" /ST 00:00
WARNING: Task may not run because /ST is earlier than current time.
SUCCESS: The scheduled task "DeviceAC" has successfully been created.
C:\WINDOWS\system32>schtasks /run /tn DeviceAC /I /Hresult
SUCCESS: Attempted to run the scheduled task "DeviceAC".
C:\WINDOWS\system32>schtasks /query /tn DeviceAC
Folder: \
TaskName Next Run Time Status
======================================== ====================== ===============
DeviceAC N/A Ready
C:\WINDOWS\system32>reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0547&PID_BC02\6&59cb9c4&0&4" /v Security
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0547&PID_BC02\6&59cb9c4&0&4
Security REG_BINARY 010004900000000000000000000000001400000002006000040000000000140000000010010100000000000512000000000018000000001001020000000000052000000020020000000014000000001001010000000000050B0000000000180000000010010200000000000F0200000001000000
C:\WINDOWS\system32>schtasks /delete /tn DeviceAC /f
SUCCESS: The scheduled task "DeviceAC" was successfully deleted.
CreateFile and DeviceIoControl work like charm. We have clean fast and synchronous Win32 code.
No crap like
task <UINT32> CUsbDev::getDeviceInfo()
{
return create_task(DeviceInformation::FindAllAsync(UsbDevice::GetDeviceSelector(0x0547, 0xAB02)))
.then([this](DeviceInformationCollection^ deviceInformationCollection) -> UINT32
{
if (deviceInformationCollection->Size > 0)
{
DeviceInformation^ di = deviceInformationCollection->GetAt(0);
String^ s = di->Id;
create_task(UsbDevice::FromIdAsync(s))
.then([this, di](UsbDevice^ usbDevice)
{
String^ s;
if (usbDevice != nullptr)
{
UsbDeviceDescriptor^ devDesc = usbDevice->DeviceDescriptor;
s = devDesc->VendorId.ToString();
s += devDesc->ProductId.ToString();
return 0;
}
else
{
return 1;
}
});
}
else
{
return 10;
}
});
}
While first method is for the developer this next method should be useful for production
The same registry settings is possible through an .inf declaration as mentioned in this link
"Specifying Access Controls for a Particular Device in the DDINSTALL.HW Section"
http://www.osronline.com/article.cfm?article=508
Off track:
If our good friend Bill was at the helm of affairs he would have never allowed junk like C++/CX extensions to have come in the first place. What sort of computer programming is it to create a thread (or task) for each procedure. Children are running away looking at the hats and decorations in C++/CX code. A clean C++ was given to this generation and what they gave to the next is unforgivable. Bill should have a glimpse of the code generated by his company today.
Now they are taking about C++/WinRt to clean the rubbish.
I believe the core of UWP is in plain Win32 C (C++) code. It is time for a complete circle to bring back VB6 to access UWP code directly, cleanly and efficiently.
Ravi