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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:52:35+00:00 2026-06-14T01:52:35+00:00

I am writing an application that used to backup some specified file, therefore using

  • 0

I am writing an application that used to backup some specified file, therefore using the backup API calls i.e CreateFile BackupRead and WriteFile API’s.

getting errors Access violation reading location.

I have attached code below.

#include <windows.h>

int main()
{
    HANDLE hInput, hOutput;

//m_filename is a variable holding the file path to read from
hInput = CreateFile(L"C:\\Key.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

//strLocation contains the path of the file I want to create.
hOutput= CreateFile(L"C:\\tmp\\", GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, NULL, NULL); 


DWORD dwBytesToRead = 1024 * 1024 * 10;
BYTE *buffer;
buffer = new BYTE[dwBytesToRead];
BOOL bReadSuccess = false,bWriteSuccess = false;
DWORD dwBytesRead,dwBytesWritten;
LPVOID lpContext;
//Now comes the important bit:

do
{
    bReadSuccess = BackupRead(hInput, buffer, sizeof(BYTE) *dwBytesToRead, &dwBytesRead, false, true, &lpContext);

    bWriteSuccess= WriteFile(hOutput, buffer, sizeof(BYTE) *dwBytesRead, &dwBytesWritten, NULL); 

}while(dwBytesRead == dwBytesToRead);

return 0;

}

Any one suggest me how to use these API’s?

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-06-14T01:52:37+00:00Added an answer on June 14, 2026 at 1:52 am

    Read the documentation. Specifically, the second paragraph of the documentation for BackupRead:

    You must set the variable pointed to by lpContext to NULL before the first call to BackupRead for the specified file or directory.

    Your code is also in dire need of error handling–you do no checking for errors at all, when in fact many of these APIs may fail (check the documentation for each API to learn how the function may fail and what happens when it fails). You should also implement correct resource handling, e.g. by closing the file handles.

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

Sidebar

Related Questions

I'm writing an API on Android that will be used by an existing application,
I'm writing a wrapper application that will be used to provide an abstraction layer
Hello I'm writing an application that uses the compatibility library and i'm using a
I'm writing an application that will be used in a mobile environment where network
We are writing an application that compiles with both gcc and Visual C++. Some
We are writing a WPF based application that is usually used on a touchscreen
I am writing a WPF application that has an optional dependency on an API
I am writing an iPhone application that will be used to find the line
I am writing an application that uses GWT, some Spring MVC and Spring Security.
I'm writing an application that manipulates a text file. The first half of my

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.