locked
Accessing printers

    Question

  • I have a a sample from MSDN that enumerate devices in the system( Printers, Fax etc) using DeviceInformation::FindAllAsync(). I read that in order to access devices and issue IOCTL commands to the devices, the device meta data should be added to the application and also the device interface should be marked as "Retricted". Then only we can issue IOCTL commands against the devices. My questions are

    1 .Do we have to do these steps in order to access printers? The above app does not seem to these steps this and it still can get the device name, id etc. Or are these steps only meant for special devices?

    2. I could do the intitial set up to issue IOCTL commands against a printer by the following code:

    ICreateDeviceAccessAsync *pCreateDeviceAccessAsyncPointer = 0;
     IDeviceIoControl *pDeviceIoControlObject = 0;
     ULONG Retlen = 0;
     UCHAR Outbuffer[10] = {0};
     UCHAR Inbuffer[10] = {0};
     
     void* pObjectUnknown = 0;
      
    LPCWSTR lpDeviceInterfacePath = "SomePath";
     String^ DevPath =  "SomePath";
     HRESULT hr = CreateDeviceAccessInstance( DevPath->Data(),
               GENERIC_READ,
               &pCreateDeviceAccessAsyncPointer );
     if( S_OK == hr )
     {
     hr = pCreateDeviceAccessAsyncPointer->QueryInterface( IID_IDeviceIoControl,&pObjectUnknown );
     if( S_OK == hr )
     {
     }
    }
    The device interface path I know .The above code is trying to access a usb printer and issue an IOCTL command aginst it. Since I have not added any meta data and Restricted mode, is this OK to do so? The HRESULS for each call is returning S_OK.
    • Edited by its_me_here Thursday, March 15, 2012 4:15 AM To add some more content
    Thursday, March 15, 2012 4:13 AM

Answers

  • Using the Windows.Devices.Enumeration.* interfaces are the equivalent of the SetupAPI methods that are available on the desktop.

    We recommend that you do bidirectional communication with the printer using Bidi (http://msdn.microsoft.com/en-us/library/windows/hardware/ff545157(v=vs.85).aspx). This is supported from Metro style device apps for printers that are installed with v4 print drivers. For USB devices, we don't support sending IOCTL commands to a device via our USB Bidi extender, though. We only support using bulk operations to get Bidi status.

    Are you able to use bulk operations for your scenario? Otherwise, if you can provide some concrete technical details, we'll take it into consideration on future releases.

    Thanks

    Justin

    Tuesday, March 20, 2012 4:29 PM

All replies

  • Its me here,

    I will look into this for you.

    Best Wishes - Eric

    Thursday, March 15, 2012 4:31 AM
    Moderator
  • We do not recommend that any device class that is supported in Windows by a driver stack (eg printers, scanners, WPD devices) utilize the IOCTL route for device communication, since you're bypassing the entire driver stack. This will lead to a much more expensive development process than using a driver and the associated stack.

    What scenario are you trying to accomplish?

    Thanks

    Justin

    Thursday, March 15, 2012 5:34 AM
  • Thank you Justin for your reply.


    The scenario is we have an existing application that enumerates printers( consider usb printers) and gets the details as to whether the printer has driver issue, port issue etc. I think we are not depending fully on the printer driver because the basic driver is installed when the printer is connected. This app is to be converted to Metro style. We are sending several IOCTL commands to the end point to read some data. Let that wait. To check if a printer has any driver issue or port issue etc, we are currently reading some values of that device from registry and checking those values. But since metro apps are not supposed to read from registry, are there some other ways to detect these issues? I can enumerate printers using DeviceEnumeration API in WinRT. These give some idea as to whether the printer has any problems or not. Only a property( HasProblem )is obtained. This is not enough.

    I have two more questions:

    1. Can I use SetupAPI in Metro style apps to get a device collection? If no, any equivalents? Is the Windows.Devices.Enumeration or Windows.Devices.Enumeration.pnp the equivalent of getting device collection in Metro style apps?

    2. Earlier if we needed to issue an IOCTL commands to a device handle, we could issue a CreateFile() call and using that handle returned we could issue an IOCTL command and get the required value. Is this route now recommended in Merto style apps with CreateFile2 api? Thanks in advance..

    Thursday, March 15, 2012 11:44 AM
  • Using the Windows.Devices.Enumeration.* interfaces are the equivalent of the SetupAPI methods that are available on the desktop.

    We recommend that you do bidirectional communication with the printer using Bidi (http://msdn.microsoft.com/en-us/library/windows/hardware/ff545157(v=vs.85).aspx). This is supported from Metro style device apps for printers that are installed with v4 print drivers. For USB devices, we don't support sending IOCTL commands to a device via our USB Bidi extender, though. We only support using bulk operations to get Bidi status.

    Are you able to use bulk operations for your scenario? Otherwise, if you can provide some concrete technical details, we'll take it into consideration on future releases.

    Thanks

    Justin

    Tuesday, March 20, 2012 4:29 PM