Hi All,
what is method to get all availabled disk drives and their status. By status I mean whether they are hard disk or CD/DVD or USB? Also how to get list of Drives in *nix?
Thanks a lot

Hi All,
what is method to get all availabled disk drives and their status. By status I mean whether they are hard disk or CD/DVD or USB?

Practically impossible.

Also how to get list of Drives in *nix?
Thanks a lot

*nixes could be very different. In most important cases parsing /proc/diskstats does what you want.

Practically impossible.

Why is it impossible? How do Dialogs get info about disks?
Ok what I want to do I get Disk lists (C: D: etc) and nail them on wxTreeCtrl and then traversing in each Node of Disk, enumerating folders and lastly files. I don't want to involve File/DIR dialogs as it needs no user interaction. So what would be the trick?
(Whether a wxWidgets trick or C++/Win32/QT.....et al)

Thanks

I decided to start on MSW and I have got it from MSDN.
It is a C code and I would like to convert it to C++ (Strangely I made C++ project in C::B and and compiled code and voila it ran!). Also there are some stuffs like TCHAR that I don't understand. So help me guys. Below is the code

// crt_getdrives.c
// This program retrives and lists out
// all the logical drives that are
// currently mounted on the machine.
//from MSDN

//QN: I want them as MS wxArrayString
//I want them in C++ not C
// I want to know CD/HDD as Well as USB

#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szDrvMsg[] = _T("A:\n"); //what does g_szDrvMsg do and what is TCHAR type?

int main(int argc, char* argv[]) {
   ULONG uDriveMask = _getdrives(); //what is ULONG equivalent of C++ or it is just ULONG?

   if (uDriveMask == 0)
   {
      printf( "_getdrives() failed with failure code: %d\n",
              GetLastError()); //So GetLastError retuns a sring or char*?
   }
   else
   {
      printf("The following logical drives are being used:\n");

      while (uDriveMask) {
         if (uDriveMask & 1)
            printf(g_szDrvMsg);

         ++g_szDrvMsg[0];
         uDriveMask >>= 1;
      }
   }
}

I decided to start on MSW and I have got it from MSDN.
It is a C code and I would like to convert it to C++ (Strangely I made C++ project in C::B and and compiled code and voila it ran!). Also there are some stuffs like TCHAR that I don't understand. So help me guys. Below is the code

// crt_getdrives.c
// This program retrives and lists out
// all the logical drives that are
// currently mounted on the machine.
//from MSDN

//QN: I want them as MS wxArrayString
//I want them in C++ not C
// I want to know CD/HDD as Well as USB

#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szDrvMsg[] = _T("A:\n"); //what does g_szDrvMsg do and what is TCHAR type?

int main(int argc, char* argv[]) {
   ULONG uDriveMask = _getdrives(); //what is ULONG equivalent of C++ or it is just ULONG?

   if (uDriveMask == 0)
   {
      printf( "_getdrives() failed with failure code: %d\n",
              GetLastError()); //So GetLastError retuns a sring or char*?
   }
   else
   {
      printf("The following logical drives are being used:\n");

      while (uDriveMask) {
         if (uDriveMask & 1)
            printf(g_szDrvMsg);

         ++g_szDrvMsg[0];
         uDriveMask >>= 1;
      }
   }
}

TCHAR
As for the other things, my psychic powers are limited today. Must be sunspots.

Thanks for reply. Hope others will too

>>what is ULONG equivalent of C++ or it is just ULONG?
It is typedefed via <windows.h>, and is documented in Windows Data Types
That's a good page to lookup the data types and #defines used by Windows.

>>GetLastError()); //So GetLastError retuns a sring or char*?
No, see GetLastError Function. In general, the Windows API functions are documented in MSDN, so you can use MSDN as your primary reference.

>> //what does g_szDrvMsg do and what is TCHAR type?
Debug the while() loop there step by step so you'll understand how the thing works ;)

>>what is ULONG equivalent of C++ or it is just ULONG?
It is typedefed via <windows.h>, and is documented in Windows Data Types
That's a good page to lookup the data types and #defines used by Windows.

>>GetLastError()); //So GetLastError retuns a sring or char*?
No, see GetLastError Function. In general, the Windows API functions are documented in MSDN, so you can use MSDN as your primary reference.

>> //what does g_szDrvMsg do and what is TCHAR type?
Debug the while() loop there step by step so you'll understand how the thing works ;)

Thanks for informative post

Ok,
I got wxWidgets function to deal with that which served me alot of pains. Now I have to determine the drive type
I got MSDN link to a function GetDriveType

And here is what it says:

UINT WINAPI GetDriveType( __in_opt  LPCTSTR lpRootPathName);

my problem is with these winAPI macros like LPCSTR and UINT
I guess (just at looking) UINT might be alias for unsigned int but have no even clue of what LPCSTR is (string??)

So please help me remove fogs in my understanding on this issue
Thanks

Ime reading this right now but feel free to teach me anything. I'll always be learning.

my problem is with these winAPI macros like LPCSTR and UINT
I guess (just at looking) UINT might be alias for unsigned int

Correct!

but have no even clue of what LPCSTR is (string??)

It a Long Pointer to Constant STRing which is essentially a const char* [edit] I just now noticed your second post and it appears that you already found the answer yourself.

Correct me if im wrong but from what I have read writing UINT is the same as unsigned int and writing LPCSTR is the same as wrting const char*

is that so?

niek_e
Thanks for reply.
I didn't see that you have already answered my Question.
where can I get a list of these WINAPI macros and their meaning?

Thanks you for replying

where can I get a list of these WINAPI macros and their meaning?

Oh c'mon, haven't you tried Windows Data Types??

Depending on which IDE you have, you might be able to quickly locate these things by placing the cursor on a given typedef/define and do a "go to declaration/definition" from the IDE's context menu. Check whether your IDE supports that, however you may find the all the #ifdef/#else blocks in the headers a bit confusing.

Oh c'mon, haven't you tried Windows Data Types??

I'm checking


Depending on which IDE you have, you might be able to quickly locate these things by placing the cursor on a given typedef/define and do a "go to declaration/definition" from the IDE's context menu. Check whether your IDE supports that, however you may find the all the #ifdef/#else blocks in the headers a bit confusing.

I use code::blocks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.