locked
Metro style app + DLL + Special device

    Question

  • Background:

    I have a special device which is being managed by the XYZ driver. Now, in order to facilitate the communication with the driver, I have created a DLL. This DLL uses GUID and SetupDI APIs to enumerate the device interfaces. Once the interfaces are enumerated, I am using the CreateFile to open the device. The desktop application uses this DLL to communicate with/use the device.

    Issue:

    I am designing the Metro-style application to serve the same functionality as desktop app. I have gone through the BUILD conference video and aware of (1) application manifest, (2) device metadata and (3) privileged interface property. I have done all that, but still the CreateFile is failing. It seem to me that I need to replace "CreateFile" with "CreateDeviceAccessInstance" and "SetupDi.. " with "Windows::Device::Enumeration". However, I am not able to find Windows class in my DLL project.

    Any guidance in resolving the issue would be very useful.

    Thanks

    Friday, January 20, 2012 9:20 PM

Answers

All replies

  • Hi U_K,

    Thank your for your question.  You are correct that you need to use IDeviceIoControl (starts with CreateDeviceAccessInstance) and Windows::Device::Enumeration.  It's hard to tell without more details why you are unable to find the Windows class in your DLL project.   One thing that might help you is taking a look at our MoFX2 sample App which "Demonstrates use of the CreateDeviceAccessInstance and IDeviceIoControl APIs to access a custom device".

    If you are still having issue after taking a look at this sample, please let us know and we will do our best to assist you!


    Thanks,

    Ben

    Saturday, January 21, 2012 12:05 AM
  • Hi Ben,

    Thanks for your reply. I have downloaded the MoFx2App along with the FX2 driver. It seems that "Windows" class is defined in the "collection.h" file. However, when I try including this file in my DLL project, VS2011/VS2010 is not able to find this file.

    My DLL project is currently not using any .NET framework, CLR etc. Its very simple C++ project with calls to my custom driver. Not sure what is missing. 

    Thanks

    Saturday, January 21, 2012 2:09 AM
  • Hi U_K,

    Sorry for the delay.  Let me follow up with some of my coworkers and see if I can get an answer for you.

     

    Thanks,

    Ben

    Thursday, January 26, 2012 9:00 PM
  • Hi U_K,

     

    When you say "Windows" class, do you mean the Windows Namespace? Are you trying to access the Windows::Devices::Enumeration namespace, for example?  Most all of the Windows::** namespace should be contained within Windows.winmd. You should see Windows.winmd under the Project's "External Dependencies" when you create VS2011 project for either "Visual C++ -> Windows Metro style -> Blank Dynamic-Link Library" or "Visual C++ -> Windows Metro style -> WinRT Component DLL".  Did you create your DLL project using one of these starting templates?

     

    The MoFX2App + DLL show a pattern where you use the enum APIs to find your device in your Metro App, and then your DLL only talks to your device using IDeviceIoControl.  You can try this approach as an alternative, though you should definitely be able to use the WinRT enumeration APIs from your DLL.

     

    Thanks,

    Ben

    Thursday, January 26, 2012 11:23 PM
  • Hi Ben,

    Thanks for the reply. Yes, I mean Windows Namespace. I have taken reference from MoFX2App and added code to use Windows::Devices::Enumeration namespace in my DLL project.

    Actually, I have not created the project with VS2011 using any of the templates that you have specified. I had a DLL project working on VS2010, I had opened the same project on VS2011 and modified it to use Windows::Devices::Enumeration APIs instead of using SetupDI APIs. Does Metro-style/WinRT DLLs have some specific settings than DLL created using VS2010?

    Thanks

    UK


    • Edited by U__K Friday, January 27, 2012 1:22 AM
    Friday, January 27, 2012 1:21 AM
  • Hi Ben,

    For now, I am modifying the MoFx2App to communicate with my custom driver. But, I would still wait for your reply on how to migrate existing DLL project (created using VS2010) to make work with Metro App in VS2011.

    Thanks,

    UK

    Friday, January 27, 2012 9:57 PM
  • Does Metro-style/WinRT DLLs have some specific settings than DLL created using VS2010?

    Hi UK,

     

    I will work on getting you an answer to this question.

     

    Thanks,

    Ben

    Monday, January 30, 2012 11:12 PM
  • Hi U_K,

     

    When you say "Windows" class, do you mean the Windows Namespace? Are you trying to access the Windows::Devices::Enumeration namespace, for example?  Most all of the Windows::** namespace should be contained within Windows.winmd. You should see Windows.winmd under the Project's "External Dependencies" when you create VS2011 project for either "Visual C++ -> Windows Metro style -> Blank Dynamic-Link Library" or "Visual C++ -> Windows Metro style -> WinRT Component DLL".  Did you create your DLL project using one of these starting templates?

     

    The MoFX2App + DLL show a pattern where you use the enum APIs to find your device in your Metro App, and then your DLL only talks to your device using IDeviceIoControl.  You can try this approach as an alternative, though you should definitely be able to use the WinRT enumeration APIs from your DLL.

     

    Thanks,

    Ben

    Hi Ben,

    >The MoFX2App + DLL show a pattern where you use ...

    Does the pattern of MoFx2App + DLL is the only pattern to conmunicate with custom device?

     

    If I onyl have a driver file (*.sys) and a Metro style app, the Metro style app cannot access the driver, i.e, sending a custom IOCTL to the driver. Right?

     

    Thanks,

     

    Best wishes,

    Tuesday, January 31, 2012 6:58 AM
  • Metro Style apps are unable to use the standard CreatFile, DeviceIoControl and Close handle calls.

    Tuesday, January 31, 2012 7:20 PM
    Moderator
  • Hi Ben,

    For now, I am modifying the MoFx2App to communicate with my custom driver. But, I would still wait for your reply on how to migrate existing DLL project (created using VS2010) to make work with Metro App in VS2011.

    Thanks,

    UK


    Ben,

     

    Are you hoping to use the standard CreatFile, DeviceIoControl, Closehandle APIs?

    Tuesday, January 31, 2012 7:22 PM
    Moderator
  • Hi Eric,

    I am not using the CreateFile, DeviceIoControl APIs. I am using the CreateDeviceAccessInstance and IDeviceIoControl as suggested int the BUILD presentations.

    Thanks

    Thursday, March 1, 2012 8:08 PM
  • It may be possible to convert from VS 10 to VS 11 however it might be worth starting with a fresh VS 11 project and moving your code over. 

    Friday, March 2, 2012 4:50 AM
    Moderator
  • Hi Eric,

    Thanks for the reply. I have tried narrow down the issue. It seems to be resolved, but still I need to migrate some more application code before the full project is compilable. Even after converting the project to VS11, it was still using the older runtime. When I changed the runtime to 110, the some of the compilation error were removed?

    I have seen that MoFx2App has the enumeration in front-end (Windows::Devices::Enumeration). Is there any example which shows the Windows::Devices::Enumeration in the native code in C++?

    Thanks


    • Edited by U__K Friday, March 2, 2012 5:22 AM
    Friday, March 2, 2012 5:21 AM
  • U_K,

    Currently we only have the one way for the MoFx2App.  However check out the DeviceEnumeration sample.

    Best Wishes - Eric

    Friday, March 2, 2012 7:59 PM
    Moderator
  • Hi Eric,

    Thanks for the reply. I have checked out DeviceEnumearation sample. But, it seems to use namespaces, IAsycOperation (task). It also uses syntax like "^" and "[this]". I have never used such syntax. Moreover, when I used Windows::Enumeration class, my VS2011 was not able to find the same.

    Could you please point me some documetation (if there is any) which explains how to migrate existing Win32DLL project to use Windows Runtime classes?

    Thanks

    Tuesday, March 6, 2012 7:13 PM
  • U_K,

    I am unaware of any documentation that shows this.

    Best Wishes - Eric

    Tuesday, March 6, 2012 8:15 PM
    Moderator
  • Hi Eric,

    DeviceInformation::FindAllAsync returns IAsyncOperation<DeviceInformationCollection>^.  In the device enumeration example a task is created for handling this async operation. Is there any other way to handle this? Is there anyway to handle this similar to sync operation?

    Thanks

    Tuesday, March 6, 2012 8:20 PM
  • U_K,

    It is async only.

    Best Wishes - Eric

    Tuesday, March 20, 2012 5:55 PM
    Moderator