Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
c++ code 2 qm
#1
I want to convert the following C++ code to QM code,

but I encountered difficulties in the last few lines of code. I searched for some information, but couldn't find a solution.

Thank you in advance for any suggestions and help.
David


Macro part qm code
Code:
Copy      Help
__Handle hf=CreateFileW(@"\\.\PhysicalDrive0" 0 0 0 OPEN_EXISTING 0 0)
if(hf=-1)
,end "failed, %s" 0 _s.dllerror

STORAGE_PROPERTY_QUERY query
query.PropertyId = StorageDeviceProperty
query.QueryType = PropertyStandardQuery
byte buffer
if !DeviceIoControl(hf, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), buffer, sizeof(buffer), 0, 0)
,end "failed, %s" 0 _s.dllerror


Cpp code:
Code:
Copy      Help
#include <Windows.h>
#include <iostream>

int main()
{
    // Get the device path of Hard Disk 0
    const wchar_t* drive = L"\\\\.\\PhysicalDrive0";

    // Open the device
    HANDLE hDevice = CreateFileW(drive, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if (hDevice == INVALID_HANDLE_VALUE)
    {
        std::cerr << "Unable to open the hard disk device" << std::endl;
        return 1;
    }

    // Get the media type
    STORAGE_PROPERTY_QUERY query{};
    query.PropertyId = StorageDeviceProperty;
    query.QueryType = PropertyStandardQuery;

    BYTE buffer[1024];
    memset(buffer, 0, sizeof(buffer));
    DWORD bytesReturned = 0;

    if (!DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), buffer, sizeof(buffer), &bytesReturned, NULL))
    {
        std::cerr << "Unable to retrieve the media type" << std::endl;
        CloseHandle(hDevice);
        return 1;
    }

    // Get the pointer to the DEVICE_DESCRIPTOR structure
    STORAGE_DEVICE_DESCRIPTOR* devDesc = reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR*>(buffer);

    // Output the results
    std::cout << "Media Type: " << static_cast<int>(devDesc->DeviceType) << std::endl;
    std::cout << "Bus Type: " << static_cast<int>(devDesc->BusType) << std::endl;

    // Close the device
    CloseHandle(hDevice);

    return 0;
}


Forum Jump:


Users browsing this thread: 1 Guest(s)