CheckCDPath.zip/CheckCDPath.cpp
#include <assert.h>
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
namespace {
bool MyGetModuleFileName(HMODULE module, wchar_t (&fileName)[_MAX_PATH]) {
if (::GetModuleFileNameW(module, fileName, _countof(fileName)) == 0) {
return false;
}
return true;
}
} // anonymous
bool CheckCDPath() {
wchar_t modulePath[_MAX_PATH];
const bool getModuleFileNameResult = MyGetModuleFileName(NULL, modulePath);
assert(getModuleFileNameResult == true);
wchar_t driveLetter[4] = L"A:\\";
driveLetter[0] += ::PathGetDriveNumberW(modulePath);
const unsigned int type = ::GetDriveTypeW(driveLetter);
return type == DRIVE_CDROM;
}