LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Enumerating WPD Devices (MTP)

I am trying to figure out how to detect/enumerate and talk to MTP devices which do not have drive letters.

 

I have the proper links form MSDN and the functions they suggest, but they do not work in CVI and am not sure how to make them work.

 

Enumerate - Enumerating WPD Devices or msdn direct link

Connecting - Connecting to a WPD Device

Sending Commands - Sending MTP Commands through WPD

 

In the past, I have just included the windows.h header and done the following two function prototypes for drive letters.

// Setup function to get present Drive Letters
DWORD WINAPI GetLogicalDriveStrings(__in   DWORD nBufferLength,__out  LPTSTR lpBuffer);


// Setup function to get Volume Names of Drives
BOOL WINAPI GetVolumeInformation(  __in_opt   LPCTSTR lpRootPathName,  __out      LPTSTR lpVolumeNameBuffer, __in       DWORD nVolumeNameSize,  __out_opt  LPDWORD lpVolumeSerialNumber,  __out_opt  LPDWORD lpMaximumComponentLength,  __out_opt  LPDWORD lpFileSystemFlags,  __out      LPTSTR lpFileSystemNameBuffer,  __in       DWORD nFileSystemNameSize);

 

However, using 

hr = CoCreateInstance(CLSID_PortableDeviceManager,
                            NULL,
                            CLSCTX_INPROC_SERVER,
                            IID_IPortableDeviceManager,
                            (VOID**) &spDevMgr)

fails with many errors.  So just need help setting up these prototypes/structs/methods.

 

Thanks

 

0 Kudos
Message 1 of 5
(5,968 Views)

Hi ngay528,

 

What errors are you seeing when you use that function?  Would you mind posting some screen shots of what you are seeing?

Also, what header files are you including?

 

 

Regards,

 

Stephanie R.

National Instruments

Stephanie R.
National Instruments
0 Kudos
Message 2 of 5
(5,951 Views)

Include Files:

 

#include <portabledevice.h>
#include <portabledeviceapi.h>
#include <wpdmtpextensions.h>
#include <windows.h>
#include "easytab.h"
#include <formatio.h>
#include <ansi_c.h>
#include <cvirte.h>     
#include <userint.h>
#include "radioGroup.h"
#include "inifile.h"
#include "Unit File Processor.h"
#include "toolbox.h"
Then with absolutely no arguments in my main c file (just includes), I get the following errors.
Unit File Processor.c - 20 errors
 "PortableDevice.h"(16,36)   Expecting an identifier.
 "PortableDevice.h"(16,36)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(16,112)   Extraneous formal parameter specification.
 "PortableDevice.h"(21,44)   Expecting an identifier.
 "PortableDevice.h"(21,44)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(21,120)   Extraneous formal parameter specification.
 "PortableDevice.h"(26,44)   Expecting an identifier.
 "PortableDevice.h"(26,44)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(26,120)   Extraneous formal parameter specification.
 "PortableDevice.h"(402,37)   Expecting an identifier.
 "PortableDevice.h"(402,37)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(402,113)   Extraneous formal parameter specification.
 "PortableDevice.h"(406,37)   Expecting an identifier.
 "PortableDevice.h"(406,37)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(406,113)   Extraneous formal parameter specification.
 "PortableDevice.h"(410,39)   Expecting an identifier.
 "PortableDevice.h"(410,39)   syntax error; found 'integer constant' expecting ')'.
 "PortableDevice.h"(410,115)   Extraneous formal parameter specification.
 "PortableDevice.h"(414,39)   Expecting an identifier.
 "PortableDevice.h"(414,39)   syntax error; found 'integer constant' expecting ')'.

 

 

Commenting out the include PortableDevice.h causes my program to compile, but have a feeling I need it to use the functions needed to enumerate.

 

 

0 Kudos
Message 3 of 5
(5,941 Views)

Hello -

 

This actually turns out to be pretty tricky...

 

  • This API is actually implemented as a COM server, primarily accessible through C++
  • This isn't normally an issue for CVI, because the ActiveX controller wizard can generate nice code for most interfaces. However, we can't generate code for this interface for two reasons:
    1. There is a bug in the way the ActiveX Controller wizard parses available type libraries. This means the controller will not be listed in the list of available controllers. This has been reported with bug ID 299606
    2. Even after I made a quick fix so that the controller would show up, this interface uses many types that CVI cannot handle automatically.

To use the API, you're going to need to do much of this manually, which can be a pretty tedious process - especially for an API this large.  I got it started for you - but there is still much work left to do.  I implemented some of the example code you listed above, and have attached it below.  Note I did this pretty quickly, so it's a little rough and not very well commented, but hopefully you should be able to get the idea.  You are likely going to need at least a rough idea of how COM works to be successful here.  Most of what's in the main implementation file comes from the header files PortableDeviceApi.h and PortableDeviceTypes.h.

 

Take a look, run through the example, and if you're unable to figure out where some of what I did came from, feel free to ask.

 

NickB_05-18_14-31-12.png

 

NickB

National Instruments

Message 4 of 5
(5,914 Views)

Kudos.

 

That is very helpful and will look to expand the function list from it such as setguids and others.

 

Thanks

0 Kudos
Message 5 of 5
(5,899 Views)