× Home


Features


Download


Purchase


API


Support

GetDeviceInfoExEx function

Retrieves following details about a MTPdrive-mapped drive letter:

Syntax

int __stdcall GetDeviceInfoExEx(
  WCHAR cDrive, 
  LPWSTR psDeviceName, int nDeviceNameLen, 
  LPWSTR psDeviceAlias, int nDeviceAliasLen, 
  LPWSTR psDeviceSerial, int nDeviceSerialLen,
  LPWSTR psDeviceStorageName, int nDeviceStorageNameLen,
  LPWSTR psDevicePropertiesJson, int nDevicePropertiesJsonLen
);

Parameters

cDrive

The drive letter to get the details about.

psDeviceName

A pointer to the buffer that receives the device name.

nDeviceNameLen

The length of the buffer for the device name string, in WCHARs. The buffer length must include room for a terminating null character.

psDeviceAlias

A pointer to the buffer that receives the device alias.

nDeviceAliasLen

The length of the buffer for the device alias string, in WCHARs. The buffer length must include room for a terminating null character.

psDeviceSerial

A pointer to the buffer that receives the device's serial number.

nDeviceSerialLen

The length of the buffer for the device's serial number string, in WCHARs. The buffer length must include room for a terminating null character.

psDeviceStorageName

A pointer to the buffer that receives the device's storage name associated with the given drive letter.

nDeviceStorageNameLen

The length of the buffer for the device's storage name string, in WCHARs. The buffer length must include room for a terminating null character.

psDevicePropertiesJson

A pointer to the buffer that receives the device properties as a JSON string.

nDevicePropertiesJsonLen

The length of the buffer for the device properties JSON string, in WCHARs. The buffer length must include room for a terminating null character.

Return Value

If the function succeeds, the return value is zero and the psDeviceName, psDeviceName, psDeviceName, psDeviceStorageName, and psDevicePropertiesJson contain the details about the given drive letter.

If the function fails, the return value is negative number. See the Example for more details about possible error codes.

Requirements

The API function only works in registered version of the MTPdrive. If called in trial version the API function returns error code -2.

Example

#include <windows.h>
#include <stdio.h>

typedef int(__stdcall *PFN_GETDEVICEINFOEXEX)(WCHAR cDrive, LPWSTR psDeviceName, int nDeviceNameLen, LPWSTR psDeviceAlias, int nDeviceAliasLen, LPWSTR psDeviceSerial, int nDeviceSerialLen, LPWSTR psDeviceStorageName, int nDeviceStorageNameLen, LPWSTR psDevicePropertiesJson, int nDevicePropertiesJsonLen);

//---------------------------------------------------------------------------
// API error codes
//---------------------------------------------------------------------------
#define MTPDRIVEAPI_ERROR_SUCCESS           0
#define MTPDRIVEAPI_ERROR_FAILURE          -1
#define MTPDRIVEAPI_ERROR_NOLICENSE        -2
#define MTPDRIVEAPI_ERROR_INVALIDARG       -3
#define MTPDRIVEAPI_ERROR_INVALIDDRV       -4
#define MTPDRIVEAPI_ERROR_CANNOTCREATEFILE -5

//---------------------------------------------------------------------------
// API string size limits
//---------------------------------------------------------------------------
#define MAX_DEVICE_NAME_LEN          100
#define MAX_DEVICE_ALIAS_LEN         20
#define MAX_DEVICE_SERIAL_LEN        MAX_PATH

int main(int argc, char* argv[])
{
  HMODULE hDll;
  int nResult = 0;
  if ((argc != 2) || (strlen(argv[1]) != 1))
  {
    printf("Usage: APItestGetDeviceInfoExEx.exe S\n");
    printf("\tGets details about drive letter S:\n");
    return 1;
  }

  SetDllDirectory("c:\\Program Files\\MTPdrive");
  hDll = LoadLibrary("MTPdrive.dll");
  if (hDll)
  {
    PFN_GETDEVICEINFOEXEX pGetDeviceInfoExEx = (PFN_GETDEVICEINFOEXEX)GetProcAddress(hDll, "GetDeviceInfoExEx");
    if (pGetDeviceInfoExEx)
    {
      WCHAR cDrive = argv[1][0];
      WCHAR sDeviceName[MAX_DEVICE_NAME_LEN];
      WCHAR sDeviceAlias[MAX_DEVICE_ALIAS_LEN];
      WCHAR sDeviceSerial[MAX_DEVICE_SERIAL_LEN];
      WCHAR sDeviceStorageName[MAX_PATH];
      WCHAR sDevicePropertiesJson[500];

      nResult = pGetDeviceInfoExEx(cDrive, sDeviceName, ARRAYSIZE(sDeviceName), sDeviceAlias, ARRAYSIZE(sDeviceAlias), sDeviceSerial, ARRAYSIZE(sDeviceSerial), sDeviceStorageName, ARRAYSIZE(sDeviceStorageName), sDevicePropertiesJson, ARRAYSIZE(sDevicePropertiesJson));
      if (nResult == MTPDRIVEAPI_ERROR_SUCCESS)
      {
        printf("Drive letter     : %c\n", toupper(cDrive));
        printf("Device Name      : %ls\n", sDeviceName);
        printf("Device Alias     : %ls\n", sDeviceAlias);
        printf("Device Serial    : %ls\n", sDeviceSerial);
        printf("Device Storage   : %ls\n", sDeviceStorageName);
        printf("Device Properties: %ls\n", sDevicePropertiesJson);
      }
      else
      {
        printf("Result: %d\n", nResult);
      }
    }
    else
    {
      printf("Cannot load function GetDeviceInfoExEx\n");
      nResult = 2;
    }
    FreeLibrary(hDll);
  }
  else
  {
    printf("Cannot load library MTPdrive.dll\n");
    nResult = 3;
  }
  return nResult;
}
         

See Also