[CFAPI] file handle from CfGetWin32HandleFromProtectedHandle cannot be used to read data.

Aaron Liu 0 Reputation points
2025-12-03T09:20:21.8733333+00:00

Hi,

I'm trying to implement a sync logic to upload local change to cloud. In this case I need to open local file for read, but it does not work as expected:

  1. Get a protected handle protected_handle from CfOpenFileWithOplock, works fine;
  2. Get a win32 handle win32_handle from CfReferenceProtectedHandle, then CfGetWin32HandleFromProtectedHandle, no errors.
  3. Try to read using the win32 handle, go the error { code: 87, kind: InvalidInput, message: "The parameter is incorrect." }

I tried to dump the handle value, protected_handle=0x21e028574a1 looks a legit handle value, but win32_handle=0x808 looks weird, is this a expected handle value?

Also I want to confirm if my approach is correct for my scenario. Any help would be great. thanks!

Windows development | Windows API - Win32
{count} votes

1 answer

Sort by: Most helpful
  1. Damien Pham (WICLOUD CORPORATION) 1,345 Reputation points Microsoft External Staff Moderator
    2025-12-03T10:57:43.66+00:00

    Hello @Aaron Liu ,

    Thank you for reaching out.

    Based on your description, your approach seems correct. For error like InvalidInput, there are a few things you can check for:

    • Protected handle validity — ensure you didn’t already close it or lose it due to an oplock break.
    • Oplock callbacks — make sure you acknowledge any oplock break promptly.
    • Handle lifetime — don’t hold the Win32 handle too long; use it briefly and close it.
    • Share/access modes — verify the access flags passed to CfOpenFileWithOplock aren’t conflicting.
    • Interference — antivirus or indexing can steal/break the lock.
    • Correct cleanup — close the Win32 handle with CloseHandle, and the protected handle with CfCloseHandle.

    I hope this is helpful for your issue. If it does not work, I would appreciate if you can provide me more detail of the issue.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.