Access violation C++ (Deleting items in a vector)

Posted by Gio Borje on Stack Overflow See other posts from Stack Overflow or by Gio Borje
Published on 2011-01-14T03:29:57Z Indexed on 2011/01/14 3:53 UTC
Read the original article Hit count: 124

Filed under:
|
|
|

I'm trying to remove non-matching results from a memory scanner I'm writing in C++ as practice. When the memory is initially scanned, all results are stored into the _results vector.

Later, the _results are scanned again and should erase items that no longer match.

The error:

Unhandled exception at 0x004016f4 in .exe: 0xC0000005: Access violation reading location 0x0090c000.

// Receives data

DWORD buffer;

for (vector<memblock>::iterator it = MemoryScanner::_results.begin(); it != MemoryScanner::_results.end(); ++it) {
    // Reads data from an area of memory into buffer
    ReadProcessMemory(MemoryScanner::_hProc, (LPVOID)(*it).address, &buffer, sizeof(buffer), NULL);

    if (value != buffer) {
        MemoryScanner::_results.erase(it); // where the program breaks
    }
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi