Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If the function succeeds, the return value is a bitmask representing the currently available disk drives. Bit position 0 (the least-significant bit) is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Can anybody Give me an example of what does it mean ?
This is from GetLogicalDrives() functions of MSDN.

Thanks

how the code will look like. I am trying but can't figure it out. it output 116.

Why?

What I have tried:

Myself and StackOverflow. I don't know what is btimask and how to work with it.
Please help!
Posted
Updated 28-May-16 15:37pm

C++
DWORD dwDriveBitMask = GetLogicalDrives();

The result is dwDriveBitMask = 116 on your machine.

What you do is to convert it to a binary sequence. This is the bit mask.
    MSB                                 LSB
116 = 00000000 00000000 00000000 01110100 (DWORD has four bytes)

As the three upper bytes are 0, we can ignore them in this case and list the lowest byte only.
LSB 0  -> No A drive
    0  -> No B drive
    1  -> Have C drive
    0  -> No D drive
    1  -> Have E
    1  -> Have F
    1  -> Have G
    0  -> No H

Then there is the matter what you want to do with it. As you don't tell us that I will just give a small example.
Let's say you want to check if drive F is present on the PC.
Then you need to mask out the bit that represents the F drive. You do this with the bitwise AND operator &.
First you need a test mask where only the bit for the F drive is set
00100000

then you AND the values
01110100 & 00100000 = 00100000


In C++ the code will be
C++
DWORD dwDriveBitMask = GetLogicalDrives();
DWORD dwMaskDriveF = 0x20 (00100000)
if (dwDriveBitMask & dwMaskDriveF)
{
    // Do something
}
 
Share this answer
 
Comments
Richard MacCutchan 29-May-16 3:13am    
DWORD dwMaskDriveF = 0x20 (00100000)
A more readable version
DWORD dwMaskDriveF = 1 << ('F'-'A');
George Jonsson 29-May-16 4:10am    
Elegant solution, but maybe not so readable for a newbie.
Richard MacCutchan 29-May-16 4:20am    
It's more about getting people to think in "computer" terms, rather than abstract high level languages. There are far too many posts here which show that the poster really has no understanding of the basics of modern (or even less modern) digital computers.
George Jonsson 29-May-16 5:18am    
True. Many questions are about "How can I store the value 00001, the zeroes disappear in my data table"
Richard MacCutchan 29-May-16 7:19am    
It's actually quite frightening at times, knowing that these are the devlopers of tomorrow.
In a loop, create a bit mask, which is equal to 1 << N, where N is a bit number; N=0 for A, N=1 for B, and so on.
If you perform bitwise operation AND (& operator) with the return value and the mask, you will return either 0 or, non-zero value. If this value is zero, the bit is clear (there is no such logical drive), otherwise it is set (the drive is present).

That's all.

Please see: http://www.cprogramming.com/tutorial/bitwise_operators.html[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900