× Home


Features


Download


Purchase


API


Support

GetDeviceInfoEx function

Retrieves following details about a MTPdrive-mapped drive letter:

Syntax

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

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.

Return Value

If the function succeeds, the return value is zero and the psDeviceName, psDeviceName, psDeviceName, and psDeviceStorageName 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_GETDEVICEINFOEX)(WCHAR cDrive, LPWSTR psDeviceName, int nDeviceNameLen, LPWSTR psDeviceAlias, int nDeviceAliasLen, LPWSTR psDeviceSerial, int nDeviceSerialLen, LPWSTR psDeviceStorageName, int nDeviceStorageNameLen);

//---------------------------------------------------------------------------
// 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: APItestGetDeviceInfoEx.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_GETDEVICEINFOEX pGetDeviceInfoEx = (PFN_GETDEVICEINFOEX)GetProcAddress(hDll, "GetDeviceInfoEx");
    if (pGetDeviceInfoEx)
    {
      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];

      nResult = pGetDeviceInfoEx(cDrive, sDeviceName, ARRAYSIZE(sDeviceName), sDeviceAlias, ARRAYSIZE(sDeviceAlias), sDeviceSerial, ARRAYSIZE(sDeviceSerial), sDeviceStorageName, ARRAYSIZE(sDeviceStorageName));
      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);
      }
      else
      {
        printf("Result: %d\n", nResult);
      }
    }
    else
    {
      printf("Cannot load function GetDeviceInfoEx\n");
      nResult = 2;
    }
    FreeLibrary(hDll);
  }
  else
  {
    printf("Cannot load library MTPdrive.dll\n");
    nResult = 3;
  }
  return nResult;
}
         

See Also