Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:19:28+00:00 2026-05-29T10:19:28+00:00

Im writing to a file using WriteFile . That works fine. Its just a

  • 0

Im writing to a file using WriteFile. That works fine. Its just a simple string:

“Test string, testing windows functions”.

Im trying to read from the file now and compare with the string i write just to ensure its working properly. I have:

DWORD dwBytesRead;
char buff[128];
ReadFile(hFile, buff, 128, &dwBytesRead, NULL)

But its returning false for me. hFile is the handle I use when writing to the file. Can have any ideas about what might be going on?

EDIT (updated from comment):

I’m getting E_ACCESSDENIED from GetLastError(). Here is how i got hFile:

hFile = CreateFile (TEXT(movedFileName.c_str()),
                    GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:19:29+00:00Added an answer on May 29, 2026 at 10:19 am

    hFile has been opened for GENERIC_WRITE only. It needs to be opened with GENERIC_READ if you want to read from it as well as write to it:

    hFile = CreateFile (TEXT(movedFileName.c_str()),
                        GENERIC_WRITE | GENERIC_READ,
                        0,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Perl script (in Windows) that is using File::Find to index
I am writing a file using Response.WriteFile(path); My problem is that it always shows
I am writing a batch file script using Windows command and want to change
We're using the following approach to writing out text files: public void WriteFile(string filePath,
I'm writing a MIDlet which needs to write file. I'm using FileConnection from JSR-75
While writing a file using ofstream, how do I know when the file's size
I am writing to binary file using fstream and when open the file using
I'm writing to a text file using the following declaration: void create_out_file(char file_name[],long double
I am writing the below structure in to the file using Binary Writer. File
I'm having a problem writing Norwegian characters into an XML file using C#. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.