GetDeviceInfo function
int __stdcall GetDeviceInfo( WCHAR cDrive, LPWSTR psDeviceName, int nDeviceNameLen, LPWSTR psDeviceAlias, int nDeviceAliasLen, LPWSTR psDeviceSerial, int nDeviceSerialLen );
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.
If the function succeeds, the return value is zero and the psDeviceName, psDeviceName, and psDeviceName 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_GETDEVICEINFO)(WCHAR cDrive, LPWSTR psDeviceName, int nDeviceNameLen, LPWSTR psDeviceAlias, int nDeviceAliasLen, LPWSTR psDeviceSerial, int nDeviceSerialLen); //--------------------------------------------------------------------------- // 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: APItestGetDeviceInfo.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_GETDEVICEINFO pGetDeviceInfo = (PFN_GETDEVICEINFO)GetProcAddress(hDll, "GetDeviceInfo"); if (pGetDeviceInfo) { WCHAR cDrive = argv[1][0]; WCHAR sDeviceName[MAX_DEVICE_NAME_LEN]; WCHAR sDeviceAlias[MAX_DEVICE_ALIAS_LEN]; WCHAR sDeviceSerial[MAX_DEVICE_SERIAL_LEN]; nResult = pGetDeviceInfo(cDrive, sDeviceName, ARRAYSIZE(sDeviceName), sDeviceAlias, ARRAYSIZE(sDeviceAlias), sDeviceSerial, ARRAYSIZE(sDeviceSerial)); 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); } else { printf("Result: %d\n", nResult); } } else { printf("Cannot load function GetDeviceInfo\n"); nResult = 2; } FreeLibrary(hDll); } else { printf("Cannot load library MTPdrive.dll\n"); nResult = 3; } return nResult; }