c++ - Access Violation when calling LockFileEx() -
i have filemapping class allows me lock file exclusive use process using win32 api function lockfileex().
bool filemapping::lockfile(bool wait) { if (isfilelocked()) return true; // want exclusive lock. dword flags = lockfile_exclusive_lock; // if don't want thread block, have set 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 lockfileex()
call access violation:
unhandled exception @ 0x7466c2ec in tftpserver.exe: 0xc0000005:
access violation reading location 0x00000008.
the file handle m_filedesc
valid handle (mapping file memory handle works) , m_mappinglength
size_t
containing length of mapped file portion in bytes.
does have idea how fix this?
your last argument null
, while should pointer overlapped
structure. error reading location 0x00000008 corresponds documented requirement that:
you must initialize hevent member valid handle or zero.
given hevent
member comes after 2 pointers, in 32 bit compilation it'd 8 bytes beginning of structure. lockfileex
trying read hevent member, , crashes.
Comments
Post a Comment