GetDeviceInfoExEx function
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 );
cDriveThe drive letter to get the details about.
psDeviceNameA pointer to the buffer that receives the device name.
nDeviceNameLenThe length of the buffer for the device name string, in WCHARs. The buffer length must include room for a terminating null character.
psDeviceAliasA pointer to the buffer that receives the device alias.
nDeviceAliasLenThe length of the buffer for the device alias string, in WCHARs. The buffer length must include room for a terminating null character.
psDeviceSerialA pointer to the buffer that receives the device's serial number.
nDeviceSerialLenThe length of the buffer for the device's serial number string, in WCHARs. The buffer length must include room for a terminating null character.
psDeviceStorageNameA pointer to the buffer that receives the device's storage name associated with the given drive letter.
nDeviceStorageNameLenThe length of the buffer for the device's storage name string, in WCHARs. The buffer length must include room for a terminating null character.
psDevicePropertiesJsonA pointer to the buffer that receives the device properties as a JSON string.
nDevicePropertiesJsonLenThe length of the buffer for the device properties JSON string, in WCHARs. The buffer length must include room for a terminating null character.
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.
-2.
#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;
}