M
M
mynameisflipe2015-11-23 00:12:05
C++ / C#
mynameisflipe, 2015-11-23 00:12:05

How to pass a variable obtained with GetLogicalDrives() to GetDriveType()?

Recently I started to study c++ and win api, the following question arose:
is it possible, having received a bitmask of available drives, to form a drive name and pass it to GetDriveType() to determine its type?
those. something like this:

DWORD drives = GetLogicalDrives();
LPCWSTR d[4];
int n;
for (int i = 0; i < 26; i++) {
  n = ((drives >> i) & 0x00000001);
  if (n == 1) {
    d[0] = LPCWSTR(65 + i);  // символ диска
    d[1] = L":";
    d[2] = L"\\";
    d[3] = L"\0"; 
    driveType = GetDriveType(*d);
    cout << driveType << endl;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-11-23
@mynameisflipe

You need to learn what arrays and strings are in C/C++ and how strings differ from characters. Well, carefully read the description of the API functions.

UINT WINAPI GetDriveType(
  _In_opt_ LPCTSTR lpRootPathName
);

LPCTSTR - Long Pointer to Constant Tchar STRing
Your declaration
specifies an array of pointers to strings. Further in the loop, the int cast to the pointer and pointers to three different strings are written to it.
Good article - habrahabr.ru/post/164193

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question