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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:12:53+00:00 2026-06-16T07:12:53+00:00

I’m reading raw bytes from a disc and trying to print them in Hex.

  • 0

I’m reading raw bytes from a disc and trying to print them in Hex. I’m getting an “Unhandled exception at 0x666CDF46 (msvcr110d.dll) in ConsoleApp.exe: 0xC0000005: Access violation writing location 0x002EC000.” inside the for loop. My guess is I’m running off the end of the TCHAR array str but I can’t figure out why. dwBytesRead and dwSize are 4096. The for loop stops for the exception when i is 4027 and I believe it should get to 4096. Can someone shed some light on this?

int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE  hCD, hFile;
    DWORD   dwBytesRead;

    hFile = CreateFile (L"sector.dat",...);

    hCD = CreateFile (L"\\\\.\\E:", ...);

    if (hCD != INVALID_HANDLE_VALUE)
    {
        DISK_GEOMETRY         dgCDROM;

        ...

        LPBYTE lpSector;
        DWORD  dwSize = 2 * dgCDROM.BytesPerSector;  // 2 sectors

        lpSector = (LPBYTE) VirtualAlloc (NULL, dwSize,
            MEM_COMMIT|MEM_RESERVE,
            PAGE_READWRITE);

        ....

        if (ReadFile (hCD, lpSector, dwSize, &dwBytesRead, NULL)) {
            const int size = (int) dwBytesRead;
            TCHAR *str = new TCHAR[size*2+1];
            int i;

            for (i=0; i<size;i++) {
                _stprintf_s(str+2*i, (size_t) dwBytesRead, L"%02x", lpSector[i]);
            }
            str[2*i]=L'\0'; 
            OutputDebugString(str);
            ...
        }

        ...
    }
}
  • 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-16T07:12:55+00:00Added an answer on June 16, 2026 at 7:12 am

    Your use of dwBytesRead inside the call to _stprintf_s is not valid. You are telling _stprintf_s that the size of the destination buffer, for every iteration through the loop, starts at a particular point in str and extends for dwBytesRead characters. This is not true, especially as your loop iterator i reaches the end of the buffer.

    You can fix this with something like:

                _stprintf_s(str+2*i, (size*2+1) - (2*i), L"%02x", lpSector[i]);
    

    It’s hard for me to say whether this will actually fix your problem, because it’s unclear what the root of the problem really is.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.