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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:12:12+00:00 2026-05-30T09:12:12+00:00

In my c++ application I’m rying to read iso file asynchronous by createfile –

  • 0

In my c++ application I’m rying to read iso file asynchronous by createfile – with overlapped flag and after it – readfile.
however when I try this code on a simple file (txt file for example) it works. but when I run this code on iso file – it fails.
I saw in MSDN that compressed file can only read by readfile sync calls. does iso files is in this category?
if yes – do you have other suggestion how to read iso files async?

this is my code:

int _tmain(int argc, _TCHAR* argv[])
{


HANDLE hFile;
    DWORD NumberOfBytesRead = 0, dw;
    BYTE *buf = (BYTE*)malloc(BUF_SIZE*sizeof(BYTE));
    OVERLAPPED overlapped;
    overlapped.Offset = overlapped.OffsetHigh = 0;  
    memset(buf, 0, 1024);

overlapped.hEvent = CreateEvent(NULL, true, false, NULL); 
if(NULL == overlapped.hEvent)
    printf("error");

hFile = CreateFile("xxx.iso",
                  GENERIC_READ,
                  FILE_SHARE_READ,
                  NULL,
                  OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING , 
                  NULL);



if (hFile == INVALID_HANDLE_VALUE)
        printf("invalid hfile\n");

   int i;   
   i= ReadFile(hFile,
                 buf,
                 BUF_SIZE,
                 &NumberOfBytesRead,
        &overlapped);
   if( GetLastError() == ERROR_IO_PENDING)
   {


       dw = WaitForSingleObject(overlapped.hEvent, INFINITE);
    if(dw ==  WAIT_OBJECT_0)
        if (GetOverlappedResult(hFile,&overlapped,&NumberOfBytesRead, TRUE) != 0)   
        {
            if (NumberOfBytesRead != 0) 
            {
                printf("!!!\n");
            }

        }

   }

thanks

  • 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-30T09:12:14+00:00Added an answer on May 30, 2026 at 9:12 am

    You haven’t posted what value you’re using for the BUF_SIZE constant, but make sure it’s an integer multiple of the volume sector size. This is a common pitfall when using unbuffered file streams. The documentation for FILE_FLAG_NO_BUFFERING in the CreateFile() documentation says:

    There are strict requirements for successfully working with files opened with CreateFile using the FILE_FLAG_NO_BUFFERING flag, for details see File Buffering.

    The page on file buffering notes:

    As previously discussed, an application must meet certain requirements when working
    with files opened with FILE_FLAG_NO_BUFFERING. The following specifics apply:

    • File access sizes, including the optional file offset in the OVERLAPPED structure, if
      specified, must be for a number of bytes that is an integer multiple of the volume sector
      size. For example, if the sector size is 512 bytes, an application can request reads and
      writes of 512, 1,024, 1,536, or 2,048 bytes, but not of 335, 981, or 7,171 bytes.

    • File access buffer addresses for read and write operations should be physical sector
      aligned, which means aligned on addresses in memory that are integer multiples of the
      volume’s physical sector size. Depending on the disk, this requirement may not be
      enforced.

    Application developers should take note of new types of storage devices being
    introduced into the market with a physical media sector size of 4,096 bytes.

    On my system, this value is 4K and reading anything smaller than 4K at a time produces errors. In many of Microsoft’s code samples, 1K is the default buffer size, so adapting examples often leads to errors with unbuffered I/O.

    Edit: also make sure to zero out all members of the OVERLAPPED structure. You don’t set the Internal and InternalHigh members to 0. Always clear the OVERLAPPED structure in the following manner:

    OVERLAPPED overlapped;
    ZeroMemory(&overlapped, sizeof(OVERLAPPED));
    

    Then, you can set the file offset and event handle.

    Edit: also consider the following note about the lpNumberOfBytesRead parameter to ReadFile():

    Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results. […] For more information, see the Remarks section.

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

Sidebar

Related Questions

my application use 10 threads that to read a lot of html file.similar the
Application is sending email by using MFMailComposeViewController , everything works just fine. However after
Application[temp] = 8; should set the value 8 to the key temp . However,
Application stores configuration data in custom section of configuration file. This information is used
Application settings in Windows Forms is a convenient way to store application-wide properties. However,
Application flow An input file consists of multiple logical documents. Extract one input logical
Application.Run(new Main()); This line gives TypeInitializationException was unhandled after I switched from 3.5 to
Application.Run MyWorkBook.xls!Macro1 will work (run the macro called Macro1 in the MyWorkBook.xls file). Application.Run
Application lunched by a user with no read/write permissions to a specific folder. For
Application I develop requires several data sources (2 RDBMS and one file storage) to

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.