2

Windows 10 IoT documents calling a custom device using CreateFile and DeviceIoControl. https://developer.microsoft.com/en-us/windows/iot/Samples/CustomDeviceAccessor

Is this same available for an Enterprise App in Windows 10? What we have is a custom USB hardware based on Cypress Fx2. We also have custom driver that uses shared memory for some very efficient Isochronous transfers. All works fine with Win32. Now we would like to move to UWP. We prefer the programming model of the win32 APIs to Windows.Devices.Usb as the later would take us years in porting. Also we need the performance of shared memory and Isochronous support. Permitting our device to be accessed using Win32 as documented in Windows IoT would be immensely beneficial. Those guidelines recommended in IoT do not seem to work in the desktop. I am unable to "Grant Access to AppContainer Processes" by modifying the Security registry key and CreateFile fails with "access denied". Am I missing something or CreateFile is entirely blocked in the UWP even for enterprises? TIA Ravi

Ravi Ganesh
  • 109
  • 8

1 Answers1

3

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

Ravi Ganesh
  • 109
  • 8
  • For some sample code on how to call win32 from vb.net in UWP refer [calling Direct 3D from vb](http://stackoverflow.com/questions/2006719/directx-with-vb-net/43110071#43110071) – Ravi Ganesh Apr 10 '17 at 15:23
  • 1
    This is a Q&A site. This is not the place for random ranting. – IInspectable Apr 10 '17 at 16:25
  • when you edit your .inf file do not forget to test sign it again, else nothing works.... – Ravi Ganesh Apr 10 '17 at 20:39
  • 1
    I think this is informative and funny ("Children are running away looking at the hats and decorations in C++/CX code."). [Besides, it looks like SO is sometimes the place for random ranting.](https://stackoverflow.com/a/1732454/4975230) – jrh Oct 05 '17 at 13:12
  • What is that binary data in the registry data? Does it need to be changed depending on the device? – Thomas Oct 18 '17 at 21:20
  • 1
    @Thomas It is supposed to be a security descriptor meaning "Grant access to XYZ, admins, users etc" So unless you want to tweak with that it is may be just copied en-mass for all devices like custom USB, HID etc – Ravi Ganesh Oct 20 '17 at 02:46
  • @RaviGanesh..For any software driver like TOASTER driver.are you able to call IOCTL from C++ UWP app? – RDX Nov 23 '18 at 09:32
  • @RDX that is the aim of this discussion ;-) – Ravi Ganesh Nov 26 '18 at 13:54
  • @RaviGanesh..CustomDeviceAccessor looks Sideloading app..am i right? – RDX Nov 27 '18 at 04:51