|
-
Dec 28th, 2001, 11:58 AM
#1
Thread Starter
Hyperactive Member
Get letter drives
im trying to get each drive on my computer. Is their a way to do this? Right now im just having it loop through four times for each drive on my computer but i want it to be portable for other computers with more or less drives.
Code:
char buff[10];
int i;
for(i=0;i<4;i++){
GetLogicalDriveStrings(10,buff);
MessageBox(NULL,buff,"dd",MB_OK);
}
this only return "A:/ "four times though.
thanks
Matt 
-
Dec 28th, 2001, 12:19 PM
#2
Monday Morning Lunatic
Code:
#include <windows.h>
#include <math.h>
#include <stdio.h>
BOOL is_drive(char letter, unsigned long drives) {
return drives & (unsigned long)pow(2, letter - 'A');
}
int main(void) {
unsigned long drvspec = GetLogicalDrives();
for(char i = 'A'; i <= 'Z'; ++i) {
if(is_drive(i, drvspec)) {
printf("Drive %c\n", i);
}
}
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 28th, 2001, 02:50 PM
#3
Thread Starter
Hyperactive Member
Parksie, do you mind explaining breifly how that works. Thanks
Matt 
-
Dec 28th, 2001, 02:52 PM
#4
Monday Morning Lunatic
GetLogicalDrives returns an unsigned long (DWORD), where drive A is bit 0, drive B is bit 1, etc.
If they're set, the drive exists. So what that does is just to check through all of them seeing if the corresponding bit is set. I suppose I could drop the call to pow and use a shift (quicker, but I can't remember which way round it is for Intel).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 28th, 2001, 03:03 PM
#5
Thread Starter
Hyperactive Member
im not sure why but I get a illegal operation whenI try and run it.
Matt 
-
Dec 28th, 2001, 03:06 PM
#6
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 28th, 2001, 03:12 PM
#7
Thread Starter
Hyperactive Member
sorry, your code was right but here was the problem.
Code:
SendMessage(drvlstS,LB_ADDSTRING,0,(LPARAM)i);
do you know why I can't set that string?
Matt 
-
Dec 28th, 2001, 03:16 PM
#8
Monday Morning Lunatic
Because i is only a single character.
Code:
char buf[2] = { i, 0 };
SendMessage(drvlstS,LB_ADDSTRING,0,(LPARAM)buf);
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 28th, 2001, 03:20 PM
#9
Thread Starter
Hyperactive Member
Matt 
-
Dec 28th, 2001, 03:24 PM
#10
Monday Morning Lunatic
No probs 
Oh yeah, anything that goes into that function must be upper case or it won't work.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2002, 10:12 AM
#11
Another version of parksies function:
PHP Code:
// add this include
#include <ctype.h>
// and for debug purposes
#include <assert.h>
BOOL is_drive(char letter, unsigned long drives) {
assert(isalpha(letter));
return drives & (1 << (toupper(letter) - 'A'));
}
I'm pretty sure that left shift is right, but you must try. If it doesn't work correctly, try
0x80000000 >> (toupper(letter) - 'A')
or stick to parksies way.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|