PrepareTape 在我的 C++ 代码中失败

PrepareTape fails in my c++ code

我用Firestreamer . I wrote a code in c++ that copies a file to that virtual tape. But when i try to prepare the tape with PrepareTapewindows功能创建了一个虚拟磁带库,但是失败了。下面是我调用 PrepareTape windows 函数的代码的一部分。

                /*Tape Handle*/
                LPCWSTR tapeName = L"\\.\Tape1";
                HANDLE tapeHandle = CreateFile(tapeName,
                    /*GENERIC_READ | GENERIC_WRITE*/  GENERIC_ALL,
                    0,
                    0,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_BACKUP_SEMANTICS,
                    0);
                if (tapeHandle == NULL)
                {
                    cout << "ERROR::Unable To Open  handle for the tape in this machine the error is ::" << GetLastError() << endl;
                }
                else
                {
                    wcout << "The Handle for the tape :" << tapeName << " is created successfully" << endl;
                }
                /*Prepare Tape*/
                DWORD prepareTApeSuccess = PrepareTape(
                    tapeHandle,
                    TAPE_LOAD,
                    TRUE
                    );

                if (prepareTApeSuccess == NO_ERROR)
                {
                    cout << "Prepare Tape successsfully executed" << endl;
                }
                else
                {
                    cout << "Prepare Tape Failed with the error :" << prepareTApeSuccess << endl;
                }
                if (!CloseHandle(tapeHandle))
                {
                    cout << "Close handle for the file is failed with thie error" << GetLastError() << endl;
                }

输出

The Handle for the tape :\.\Tape1 is created successfully
Prepare Tape Failed with the error :1

但其余所有功能,即其他磁带功能在相同句柄下工作正常。我尝试使用 GetTapeStatus 函数获取磁带的状态。磁带设备已准备好接受适当的磁带访问命令,没有 returning 错误,return 值为 NO_ERROR。

提前致谢

在prepare tape函数中考虑第三个参数,如果这个参数为TRUE,函数returns立即执行。如果为 FALSE,则函数在操作完成之前不会 return。我已将其更改为 false,我的问题已解决。