Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DeviceIoControl return Incorrect function error

DeviceIoControl return Incorrect function error

Scheduled Pinned Locked Moved C / C++ / MFC
comdebugginghelptutorialquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I am trying to achieve some information about HDD device through following code (pcwszDrive is "\\.\E:")

    STDMETHODIMP CheckFileSystem(PCWSTR pcwszDrive)
    {
    HRESULT hr = S_OK;
    HANDLE hDisk = INVALID_HANDLE_VALUE;
    ULONG BytesReturned = 0;
    FILE_SYSTEM_RECOGNITION_INFORMATION FsRi = { 0 };
    //
    // Open the target, for example "\\.\C:"
    //
    TRACE(_T("CreateFile on %s ...\n"), pcwszDrive);
    hDisk = CreateFile(pcwszDrive,
    FILE_READ_ATTRIBUTES | SYNCHRONIZE | FILE_TRAVERSE,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL, OPEN_EXISTING, 0, NULL);
    if (hDisk == INVALID_HANDLE_VALUE)
    {
    hr = HRESULT_FROM_WIN32(GetLastError());
    TRACE(_T("CreateFile failed on %s, GLE = 0x%x\n"), pcwszDrive, GetLastError());
    goto exit;
    }
    TRACE(_T("succeeded.\n\n"));
    TRACE(_T("\nPress Any Key to send down the FSCTL\n"));
    //
    // Send down the FSCTL
    //
    TRACE(_T("Calling DeviceIoControl( FSCTL_QUERY_FILE_SYSTEM_RECOGNITION )\n"));
    BOOL fResult = DeviceIoControl(hDisk,
    FSCTL_QUERY_FILE_SYSTEM_RECOGNITION,
    NULL,
    0,
    &FsRi,
    sizeof(FsRi),
    &BytesReturned,
    NULL);
    if (! fResult)
    {
    hr = HRESULT_FROM_WIN32(GetLastError());
    TRACE(_T("failed GetLastError = 0x%x\n"), GetLastError());
    goto exit;
    }
    TRACE(_T("succeeded.\n"));
    TRACE(_T("FSCTL_QUERY_FILE_SYSTEM_RECOGNITION returned success.\n"));
    TRACE(_T("FSCTL_QUERY_FILE_SYSTEM_RECOGNITION retrieved \"%S\".\n"), FsRi.FileSystem);

    exit:
    if (hDisk != INVALID_HANDLE_VALUE)
    {
    CloseHandle(hDisk);
    hDisk = INVALID_HANDLE_VALUE;
    }

    return hr;
    

    }

    This code is taken from here: Obtaining File System Recognition Information - Win32 apps | Microsoft Docs[^] But at DeviceIoControl method, I got

    failed GetLastError = 0x1

    which translated means:

    ERROR_INVALID_FUNCTION

    1 (0x1)

    Incorrect function.

    My VS2017 run as administrator mode ... what I've done wrong ?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups