Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Win32 const DRIVE_FIXED - How to? 1

Status
Not open for further replies.

RLMuller

Programmer
Mar 7, 2003
15
0
0
US
Hi,

I downloaded a TreeView C# sample. It included the statement:

if (PlatformInvokeKernel32.GetDriveType(drives) ==
PlatformInvokeKernel32.DRIVE_FIXED) ...

I found a declaration for PlatformInvokeKernel32:

using System.Runtime.InteropServices;
internal class PlatformInvokeKernel32
{
[DllImport("KERNEL32")]
public static extern int GetDriveType(string s);
}

How do I declare PlatformInvokeKernel32.DRIVE_FIXED?

TIA,

Richard
 
Winbase.h has it defined as:
Code:
#define DRIVE_UNKNOWN     0
#define DRIVE_NO_ROOT_DIR 1
#define DRIVE_REMOVABLE   2
#define DRIVE_FIXED       3
#define DRIVE_REMOTE      4
#define DRIVE_CDROM       5
#define DRIVE_RAMDISK     6
You can also find this information in the API Text Viewer utility.

Chip H.
 
Chip,

Many thanks for your reply. It exposes my stupidity, because I've searched many times through the headers for the Platform SDK, MFC and VC++ proper.

I didn't think of it because I wanted to learn how the author of the example I copied managed to use the expression PlatformInvokeKernel32.DRIVE_FIXED that was in the code. I had to add to GetDrive declaration to overcome another compiler complaint, and I assume some other declaration got omitted which would allow the subject express to be used.

I searched through all the .h's and .inl's in Visual Studio 6.0 and Platform SDK and found only identical entries in WinBase.h in each of those folders, just as you said.

Do you (or anybody) have any other idea about how to use the expression above without resorting to substituing a hard coded value?

Again, thanks for your help. I really appreciated it.

Regards,
Richard
 
Chip,

I created an enumeration based on WinBase.h values and cast the DRIVE_TYPE element to an int. It worked fine as a substitute for PlatformInvokeKernel32.DRIVE_FIXED.

What exactly is the "API Text Viewer utility?" I found the FindType utility in a VS.Net C# sample, which I think is neat for determining the "using" statement required in order to use a particular class. I assume the utility you cited is something different.

Again, thanks for your help.

Regards,
Richard
 
Whoops!

The API Text Viewer doesn't come with .NET -- it shipped with Visual Basic 5 & 6. It was a handy little utility that would provide you with all the API and constant definitions so you could make easy use of them from your VB code.

Regarding your enumeration -- no need to do the cast every time, because you can declare your enum to be of type int.
Code:
enum DriveType : int {
  DRIVE_UNKNOWN = 0,
  DRIVE_NO_ROOT_DIR = 1,
  DRIVE_REMOVABLE = 2,
  DRIVE_FIXED = 3,
  DRIVE_REMOTE = 4,
  DRIVE_CDROM = 5,
  DRIVE_RAMDISK = 6
}
C# will allow you to use any integral type, but not strings (darn it!) or floating-point values.

Glad I was of some help.

Chip H.
 
Hi Chip,

Just a few last words:

FYI, a few minor details:

The "C# Lang. Spec. (Based on Beta Content)" says the underlying type is "int" (Sec. 14.1), so ": int" is apparently redundant.

The spec also says enums have default values 0, 1, ... (just like C, etc.) (Sec. 14.3)

More importantly, there's apparently no implicit conversion from an enum element to an int (Sec. 6.1.2). At least the compiler thinks this is true 'cause I couldn't eliminate the cast no matter what combination of your and my ideas would compile without it.

Then it occurred to me to search Google to see if I could find the site where I originally got this sample. Voila, I got it from
So I posted a question there, but it's not clear I'll get any response on that site.

Finally, I looked into an API viewer. I found an interesting site offered a viewer with an up-to-date base: Take a look at it.

The download of that viewer failed, but it may be because it was getting more traffic than it could handle. I'll try late tonight.

Thanks for helping me learn C#.

Best wishes,
Richard
 
More importantly, there's apparently no implicit conversion from an enum element to an int (Sec. 6.1.2). At least the compiler thinks this is true 'cause I couldn't eliminate the cast no matter what combination of your and my ideas would compile without it.

I can see that. Your variable would be of type enum, not int (even though all the values in the enum are ints), so a cast is indeed probably necessary.

Glad to help out - you've asked some good questions!

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top