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 7414855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:11:01+00:00 2026-05-29T07:11:01+00:00

I am calling ReadFile() WinAPI to copy the file contents to a char array,

  • 0

I am calling ReadFile() WinAPI to copy the file contents to a char array, inside my VC++ code. Have placed GetLastError() immediately after ReadFile().

for( read some n no: of files)
{
FileRead(fp,destCharArray,ByesToRead,NoOfBytesRead,NULL);
int ret = GetLastError();
}

GetLastError() is returning 183 only when 1st file is read. For all
other file reads its returning 183. But eventhough 183 is returned the
contents of file are copied to charArray. And the problem is that the
file read does not happen for some 28th file (here too return status
is 183). Irrespective of successful or unsuccessful file read, 183 is
returned!

According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

error code 183 means “ERROR_ALREADY_EXISTS“.

What does the above error status signify in ReadFile() context.?

Can anyone kindly help me in figuring out why?

  • 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-29T07:11:02+00:00Added an answer on May 29, 2026 at 7:11 am

    Your code is incorrectly calling GetLastError. You should only call GetLastError if the immediately prior Win32 API call failed, and that API returns status information through GetLastError.

    Here the API in question is ReadFile. The documentation says:

    Return value

    If the function succeeds, the return value is nonzero (TRUE).

    If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, call the GetLastError function.

    In other words you must only call it if ReadFile returns FALSE.

    Your code should look something like this:

    if (!ReadFile(fp,destCharArray,ByesToRead,NoOfBytesRead,NULL))
    {
        DWORD err = GetLastError();
        // handle error probably by raising exception
    }
    

    Your code is returning the error code for an earlier failure that is unrelated to the call to ReadFile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Calling fclose() here after dup() ing its file descriptor blocks until the child process
In my FileProc class, I have four functions: ReadFile(TemplateList<char> &ReadList){} ReadFile(TemplateListAdv<char> &ReadList){} ReadFile(CharList &ReadList){}
When calling a function in my views/helpers/ file, from my script inside views/scripts/ ,
My program have several worker threads that calling a function in a dynamically loaded
Calling MyPanel.Panel1.Hide(); or MyPanel.Panel2.Hide(); simply hides the controls inside the panel... but I want
I'm watching a directory by calling ReadDirectoryChangesW synchronously. When a new file is available,
Calling all MQ Gurus, I have a box under my desk which we use
Calling multiMax() at the bottom of the code block we pass in 4 arguments.
calling ListView's setSelection() seems to have a problem. a lot of people ask about
Calling setNoRender() or indeed any methods on the viewRenderer helper seem to have no

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.