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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:39:58+00:00 2026-05-26T04:39:58+00:00

I have a FileMapping class that allows me to also lock a file for

  • 0

I have a FileMapping class that allows me to also lock a file for exclusive use by my process by using the Win32 API function LockFileEx().

bool FileMapping::lockFile(bool wait) {
    if (isFileLocked())
        return true;

    // We want an exclusive lock.
    DWORD flags = LOCKFILE_EXCLUSIVE_LOCK;

    // If we don't want the thread to block, we have to set the appropriate flag.
    if (!wait)
        flags |= LOCKFILE_FAIL_IMMEDIATELY;

    m_isFileLocked = LockFileEx(m_fileDesc, flags, 0, (DWORD) m_mappingLength, (DWORD) (((uint64_t) m_mappingLength) >> 32), NULL);
    return m_isFileLocked;
}

Whenever I get to the LockFileEx() call I get an access violation:

Unhandled exception at 0x7466c2ec in tftpServer.exe: 0xC0000005:
Access violation reading location 0x00000008.

The file handle m_fileDesc is definitely a valid handle (mapping the file into memory with that handle works) and m_mappingLength is just a size_t containing the length of the mapped file portion in bytes.

Does anybody have an idea how to fix this?

  • 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-26T04:39:58+00:00Added an answer on May 26, 2026 at 4:39 am

    Your last argument is NULL, while it should be a pointer to a OVERLAPPED structure. The error about reading location 0x00000008 probably corresponds to the documented requirement that:

    You must initialize the hEvent member to a valid handle or zero.

    Given the hEvent member comes after two pointers, in 32 bit compilation it’d be 8 bytes from the beginning of the structure. So LockFileEx is probably trying to read the hEvent member, and crashes.

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

Sidebar

Related Questions

Have an app that can use tts to read text messages. It can also
I have two table to be joined using hbm file. The scenario is as
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I am writing an app to do a file conversion and part of that
Have a photography site that I want to prevent image copying from. How can
Have a look on following application http://itunes.apple.com/us/app/fatbooth/id372268904?mt=8 i think they are using the same
I have a flat file with some repeating sections in it, and I'm confused
Have some dates in my local Oracle 11g database that are in this format:
Have any one tried to activate fancybox thumbnail gallery using a button or an

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.