locked
Windows 8 Store device apps

    Question

  • Hi,
    We are developing an windows 8 store device app using C# which will communicate to the device using Win32 API and IOCTL calls in a C dll. We had created a C dll with Create File and some IOCTL calls, imported in C# application. Integration goes well and when Create File function is called, it returns 'ACCESS DENIED ERROR'. We had also tried creating Manifest with requested Execution level to Administrator but still the issue is not solved. I would like to know whether Win32 API & IOCTL calls can be used directly or do I need to use any wrapper calls to make it work?

    Thanks in advance.

    Hi, For the above said question, I got the ppt from MSFT (refer below link) http://channel9.msdn.com/events/BUILD/BUILD2011/HW-747T I tried implementing "CreateDeviceAccessInstance" and IDeviceIoControl API for getting the handle and accessing the device but I'm getting E_INVALIDARG for function call to GetResult(). My sequence is as follow

    1. ICreateDeviceAccessAsync *pDeviceAccess

    2. CreateDeviceAccessInstance (FilePath, GENERIC_READ|GENERIC_WRITE, &pDeviceAccess) - SUCCEEDS

    3. pDeviceAccess->Wait(INFINITE) - SUCCEEDS

    4. IDeviceIoControl *pDeviceControl

    5. pDeviceAccess->GetResult(IID_IDeviceIoControl, (void **)&pDeviceControl) - Fails with E_INVALIDARG error code

    Any suggestions would be helpful. Thanks in Advance.

     
    Friday, November 16, 2012 2:39 PM

Answers

All replies

  • Hi Ash8659,

    What is the value of FilePath that you are trying to pass into CreateDeviceAccessInstance? 

    Regards,

    lisa

    Sunday, November 18, 2012 4:44 AM
  • File path value is - D:\Test.log.

    Monday, November 19, 2012 3:56 AM
  • Hi,

    Step 5: Instead of using pDeviceAccess->GetResult(), I had used pDeviceAccess->QueryInterface().  The interface returned is typecasted to DeviceIoControl pointer.  Now I don't get E_INVALIDARG.  But while issuing the IOCTL as per below, I get E_UNEXPECTED error code.

    6.  pDeviceControl->DeviceIoControlSync(FSCTL_GET_RETRIEVAL_POINTERS, (UCHAR *) <Pointer to Starting VCN input buffer>, sizeof(STARTING_VCN_INPUT_BUFFER), (UCHAR *) <Pointer to retrieval buffer pointer>, sizeof(retrieval buffer structure), &dwBytesReturned);

    Any input would be great

    Thanks,

    Ashok

    Monday, November 19, 2012 9:50 AM
  • The path passed into CreateDeviceAccessInstance needs to be the path to your custom device, not D:\Test.log. It is the same path you would have used to call CreateFile from a desktop app to send IOCTLs.

    Regards,

    lisa

    Monday, November 19, 2012 5:39 PM
  • The path passed to CreateDeviceAccessInstance is same as the path passed to CreateFile function.  My approach is to read the properties of a file first.  So I had given the path of a file.  The code which I'm using is tested and works fine when I had created as a console application using CreateDeviceAccessInstance and IDeviceIoControl, but when I try to access from C# using a C DLL it fails.
    Tuesday, November 20, 2012 4:15 AM
  • CreateDeviceAccessInstance requires device paths, not file paths.

    Regards,

    lisa


    Tuesday, November 20, 2012 4:25 AM
  • CreateFile fails because you can't access an arbitray file path such as d:\test.log from a store app.  You only have access to e.g. the pictures folder, documents folder, and app local storage as allowed by the manifest capabilities.
    Tuesday, November 20, 2012 8:04 PM
  • Lisa, could you maybe elaborate on how we deduce the "custom device path".  What makes one path valid (what does a device path look like) and what makes "D:\Test.log" invalid?

    Thanks.


    • Edited by ukdiveboy Tuesday, November 20, 2012 9:40 PM
    Tuesday, November 20, 2012 9:39 PM
  • Hi ukdiveboy,

    This sample demonstrates how to use CreateDeviceAccessInstance on a custom device: http://code.msdn.microsoft.com/windowsapps/Custom-device-access-sample-43bde679

    Basically a custom device path is a PnP interface instance path, also known as a symbolic link. It is generated by the OS based on how the device is connected to the system, and can look something like this for USB devices:

    \\?\USB#VID_1234&PID_5678#0&1dddf4f9&0&1#{SOME GUID HERE

    It will look different for other buses, e.g. ACPI

    In desktop apps, CreateFile can open both PnP paths and file paths like D:\Test.log.  For Windows Store apps, file opening and file management is done using the Window.Storage APIs.  CreateFile is not supported.

    Wednesday, November 21, 2012 6:04 AM