C++创建文件(紧凑型闪存卡写入器)
C++ createFile (Compact Flash Card Writer)
我对C++很陌生。我正在开发一个 Java 应用程序,该应用程序会调用 Jni 来C++将原始文件 (.img) 写入连接的紧凑型闪存卡写入器。下面是我的 c++ 代码,假设找到连接的 USB 驱动器,使用 createFile 创建一个句柄并将原始图像 (.img) 写入设备。最终,应用程序将使用Java JNI调用。
我现在遇到的问题是,我能够列出连接的驱动器但有问题使用 createFile() 为它们创建一个句柄。我收到以下错误:
Error 1 error C2660: 'getHandleOnVolume' : function does not take 2 arguments c:usersomisorem.novdocumentsvisual studio 2010projectsdiskrunnerdiskrunner.cpp 71 1 DiskRunner
2 IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCWSTR" c:usersomisorem.novdocumentsvisual studio 2010projectsdiskrunnerdiskrunner.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;
}
谢谢你们的投入。我最终想出了如何通过执行以下操作来解决问题:
使用类型 LPCSTR 作为文件名和 hRawDisk
LPCSTR volumename = "\\.\G:";
LPCSTR filename = "c:\somedirectory\someimage.img";
我创建了单独的函数来创建句柄,它们使用以下方法调用:
hVolume = getHandleOnVolume(wszVolume, GENERIC_WRITE);
hFile = getHandleOnFile(filename, GENERIC_READ);
为文件和卷使用类似的东西创建句柄。
HANDLE getHandleOnFile(LPCTSTR filename, DWORD access){
HANDLE hFile;
hFile = CreateFile(filename, access, 0, NULL, (access == GENERIC_READ) ? OPEN_EXISTING:CREATE_ALWAYS, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printLastError();
return 0;
}
//delete filelocation;
//CloseHandle(hFile);
printf("handle hFile created successfully n");
system("PAUSE");
return hFile;
}
我对音量重复了相同的内容。之后,我调用了DeviceIOControl来锁定和卸载设备以进行写入。
相关文章:
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 与SPI NAND闪存(STM32L4,QSPI)的通信问题
- 从不属于应用程序的闪存读取
- LittleFS文件系统,NOR闪存的文件写入问题
- STM32使用HAL库的外部闪存读取设备ID
- STM32F4 - 在运行时将函数从闪存复制到RAM
- 如何将来自闪存中不同银行的两个内存区域交换为STM32L475
- 为什么在STM32上未清除闪存页面
- 如何在看门狗执行前将日志复制到闪存?
- 一种避免pgm_read访问闪存的方法(avr 微控制器)
- g++arm none eabi从4.9升级到gcc 8.2.生成的二进制文件不再适合闪存
- 如何检查USB插槽中是否存在空闪存卡读卡器?
- 获取闪存驱动器的读写速度
- c/c++:如何知道已用闪存的大小?
- 如何以编程方式使用 MBR 和 USB 闪存扇区
- C++/C 实时闪存流处理
- 在闪存驱动器上为 Windows C++ Code blocks设置 OpenGL
- 如何限制 MFC 应用程序仅从已知的 USB 闪存驱动器运行
- C++创建文件(紧凑型闪存卡写入器)
- 了解附加模式下的闪存文件系统磨损