Can somebody please tell me why i'm getting an error. I've been trying to figure this out for a bit now.
LPCWSTR drive2[4] = { L"C:\\", L"D:\\", L"E:\\", L"F:\\" };
int i;
UINT test;
for (i = 0; i<12; i++)
{
test = GetDriveType(drive2[i]); //anything from here with "drive2[i]" is an error.
switch (test)
{
case 0: ::MessageBox(Handle, drive2[i], "0 cannot be determined", MB_OK);
break;
case 1: ::MessageBox(Handle, drive2[i], "1 invalid", MB_OK);
break;
case 2: ::MessageBox(Handle, drive2[i], "2 removable", MB_OK);
break;
case 3: ::MessageBox(Handle, drive2[i], "3 fixed", MB_OK);
break;
default: "Unknown value!\n";
LPCWSTRis an alias forconst wchar_t*.You are using the
TCHARversion of theGetDriveType()andMessageBox()functions.TCHARmaps towchar_tifUNICODEis defined at compile-time, otherwise it maps tochar.Your
drive2variable is an array ofwchar_tpointers, so in order to passdrive2[i]as-is toGetDriveType()andMessageBox(), you have to compile your project for Unicode (ie, make theUNICODEconditional be defined at compile-time), which will makeGetDriveType()map toGetDriveTypeW()andMessageBox()map toMessageBoxW()so that they accept only wide (wchar_t) strings. Otherwise,GetDriveType()will map toGetDriveTypeA()andMessageBox()will map toMessageBoxA()so they accept only narrow (char) strings.You are passing narrow string literals to
MessageBox(), which will not work when compiling for Unicode. And you can't pass wide strings toTCHARfunctions if you are NOT compiling for Unicode - which sounds like the case in your situation, as the error message is complaining about passing aconst wchar_t*pointer to aconst char*parameter.You need to use the
TEXT()macro to make string literals be wide whenUNICODEis defined, instead of being narrow.I would also suggest using
TEXT()for the string literals in yourdrive2array as well, to match theTCHARfunctions that you are passing the array elements to.Also, your loop is going out of bounds of the
drive2array.With that said, try this:
Otherwise, if you want to deal exclusively with
wchar_t(which you should be), then use the Unicode-based function definitions directly, and use wide string literals only, don't deal withTCHARat all: