我对 C++ 很陌生。我正在开发一个 Java 应用程序,该应用程序对 C++ 进行 Jni 调用以将原始文件 (.img) 写入附加的紧凑型闪存卡写入器。下面是我的 c++ 代码,假设找到一个连接的 USB 驱动器,使用 createFile 创建一个句柄并将原始图像 (.img) 写入设备。最终应用程序将使用 Java JNI 调用。
现在遇到的问题是,我能够列出连接的驱动器,但在使用 createFile() 为它们创建句柄时遇到问题。我收到以下错误:
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
任何帮助表示赞赏。
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;
}