I am pretty new to C++. I am working a Java application that makes a Jni Call to C++ to write raw file (.img) to an attached Compact Flash card writer. Below is my c++ code, it is suppose to locate a connected usb drive, create a Handle using createFile and write a raw image (.img) to the device. Eventually the application would called using Java JNI.
The issue am having now is that, am able to list the attached drives but having issues creating a Handle to them using createFile(). I am getting below errors :
Error 1 error C2660: 'getHandleOnVolume' : function does not take 2 arguments c:\users\omisorem.nov\documents\visual studio 2010\projects\diskrunner\diskrunner.cpp 71 1 DiskRunner
2 IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCWSTR" c:\users\omisorem.nov\documents\visual studio 2010\projects\diskrunner\diskrunner.cpp 86 23 DiskRunner
Any help is appreciated.
int main() {
// GetLogicalDrives returns 0 on failure, or a bitmask representing
// the drives available on the system (bit 0 = A:, bit 1 = B:, etc)
unsigned long driveMask = GetLogicalDrives();
int i = 0;
ULONG pID;
//cboxDevice->clear();
while (driveMask != 0)
{
if (driveMask & 1)
{
// the "A" in drivename will get incremented by the # of bits
// we've shifted
char drivename[] = "\\\\.\\A:\\";
drivename[4] += i;
cout << pID << "[%1:\\]" << drivename << endl;
}
driveMask >>= 1;
// cboxDevice->setCurrentIndex(0);
++i;
}
LPCTSTR volumeID = TEXT("D:");
int volumeID1 = int(volumeID);
hVolume = getHandleOnVolume(volumeID1, GENERIC_WRITE);
system("PAUSE");
return 0;
}
HANDLE getHandleOnVolume(int volume1, DWORD access)
{
HANDLE hVolume;
char volumename[] = "\\\\.\\A:";
volumename[4] += volume1;
hVolume = CreateFile("\\\\.\\F", access, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hVolume == INVALID_HANDLE_VALUE)
{
cout <<"Partition does not exist or you don\'t have rights to access it"<<endl; // tesing
}
else {
cout << "Partition exists " << endl;
}
cout << volume1;
return hVolume;
}