0
我是C++的新手。我正在開發一個Java應用程序,使Jni Call to C++將原始文件(.img)寫入附加的Compact Flash卡寫入器。下面是我的C++代碼,它是假定找到一個連接的USB驅動器,使用createFile創建一個句柄,並將一個原始圖像(.img)寫入設備。最終應用程序將使用Java JNI進行調用。C++ createFile(Compact Flash Card Writer)
現在的問題是,我能夠列出連接的驅動器,但有問題 使用createFile()爲它們創建Handle。我得到以下錯誤:
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;
}
爲什麼不使用純Java方法?它具有完美的文件IO支持,特別是自Java 7以來。 – 01es 2012-04-23 19:17:36
謝謝。從我所做的小研究中,Java似乎不支持這種低級調用,除非使用JUSB或Java-USB API,這些API已經過時並且與Windows 7不兼容。但是,如果您可以指出我在純java方向上,如果可能的話。 – stdapsy 2012-04-23 20:09:10