Click here to Skip to main content
15,918,967 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMonitoring a process Pin
SiddharthAtw31-Jan-05 18:06
SiddharthAtw31-Jan-05 18:06 
GeneralRe: Monitoring a process Pin
rwestgraham31-Jan-05 18:50
rwestgraham31-Jan-05 18:50 
GeneralRe: Monitoring a process Pin
Blake Miller1-Feb-05 4:54
Blake Miller1-Feb-05 4:54 
GeneralAutomation Server Pin
Anonymous31-Jan-05 18:05
Anonymous31-Jan-05 18:05 
GeneralCComboBox Properties Pin
LighthouseJ31-Jan-05 17:17
LighthouseJ31-Jan-05 17:17 
GeneralRe: CComboBox Properties Pin
Ryan Binns31-Jan-05 17:56
Ryan Binns31-Jan-05 17:56 
GeneralRe: CComboBox Properties Pin
LighthouseJ31-Jan-05 18:01
LighthouseJ31-Jan-05 18:01 
QuestionMapViewOfFile returning ERROR_ACCESS_DENIED? Pin
Michael Dunn31-Jan-05 16:09
sitebuilderMichael Dunn31-Jan-05 16:09 
OK, I hope this is just a silly math error, but I'm stumped so far. I'm writing a little log viewer app, and I'm slurping the whole file into memory to parse it. If the user reloads the same file, I don't want to load the whole thing again, just the new data at the end of the file.
I calculate the offsets I'll be reading from/to and the size of the chunk I'll be reading, then pass all that to CreateFileMapping/MapViewOfFile. The problem comes when the file size is over 64K (which is SYSTEM_INFO::dwAllocationGranularity), MapViewOfFile() fails with ERROR_ACCESS_DENIED. Eek! | :eek:
DWORD dwMappingStartOffset = 0,  // offset in file where the mapping starts
      dwMappingEndOffset = 0,    // offset where it ends
      dwStartingPosOffsetFromMappingStart = 0, // where to start parsing the file
                                               // (offset from dwMappingStartOffset)
      dwMappingSize = 0;  // size of file mapping object
//NOTE: m_dwLastSeenFileSize is already set to the size of the file the last time we parsed it
 
            // Get the system alloc granularity, the starting offset has to
            // be a multiple of that.
            SYSTEM_INFO si = {0};

            GetSystemInfo ( &si );
 
            // Calc the starting/ending offsets of the file that we'll read.
            dwMappingStartOffset = m_dwLastSeenFileSize;
            dwStartingPosOffsetFromMappingStart = dwMappingStartOffset % si.dwAllocationGranularity;
            dwMappingStartOffset -= dwStartingPosOffsetFromMappingStart;
            dwMappingEndOffset = dwFileSize - 1;
            dwMappingSize = dwMappingEndOffset - dwMappingStartOffset + 1;
 
    // Map the file (or just the end part) into memory.
    //NOTE: hFile was already opened w/CreateFile
HANDLE hMapping = CreateFileMapping ( hFile, NULL, PAGE_READONLY, 0, dwMappingSize, NULL );
 
    if ( NULL == hMapping )
        {
        CloseHandle ( hFile );
        return false;
        }
 
void* pvFileData = MapViewOfFile ( hMapping, FILE_MAP_READ, 0, dwMappingStartOffset, dwMappingSize );
 
    if ( NULL == pvFileData )
        {
        CloseHandle ( hMapping );
        CloseHandle ( hFile );
        return false;
        }
The other odd thing is that if I change dwMappingSize to 0 on the CreateFileMapping() call - making the file mapping object the size of the whole file - it works fine. I could just do that, but this problem is bugging me, and I'll keep thinking about it until I solve it. Wink | ;)

--Mike--
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb
Strange things are afoot at the U+004B U+20DD

AnswerRe: MapViewOfFile returning ERROR_ACCESS_DENIED? Pin
Ryan Binns31-Jan-05 17:53
Ryan Binns31-Jan-05 17:53 
GeneralRe: MapViewOfFile returning ERROR_ACCESS_DENIED? Pin
Michael Dunn1-Feb-05 6:51
sitebuilderMichael Dunn1-Feb-05 6:51 
GeneralRe: MapViewOfFile returning ERROR_ACCESS_DENIED? Pin
Ryan Binns1-Feb-05 12:47
Ryan Binns1-Feb-05 12:47 
Generalword seperating algorithm Pin
jonavon blakly31-Jan-05 15:51
jonavon blakly31-Jan-05 15:51 
GeneralRe: word seperating algorithm Pin
David Crow31-Jan-05 16:40
David Crow31-Jan-05 16:40 
GeneralRe: word seperating algorithm Pin
jonavon blakly9-Feb-05 15:59
jonavon blakly9-Feb-05 15:59 
GeneralRe: word seperating algorithm Pin
David Crow10-Feb-05 5:28
David Crow10-Feb-05 5:28 
Generalquickcam project Pin
mark18231-Jan-05 14:33
mark18231-Jan-05 14:33 
GeneralRe: quickcam project Pin
mcsherry31-Jan-05 21:48
mcsherry31-Jan-05 21:48 
QuestionWho can help me about hooks using hot-key? Pin
TTT8131-Jan-05 14:02
TTT8131-Jan-05 14:02 
AnswerRe: Who can help me about hooks using hot-key? Pin
RicoH1-Feb-05 0:39
RicoH1-Feb-05 0:39 
GeneralIgnore Windows key + M Pin
Mike Hell31-Jan-05 12:36
Mike Hell31-Jan-05 12:36 
GeneralWM_PAINT seems not working Pin
int01hh31-Jan-05 12:28
int01hh31-Jan-05 12:28 
GeneralRe: WM_PAINT seems not working Pin
beerboy_2231-Jan-05 13:31
beerboy_2231-Jan-05 13:31 
GeneralRe: WM_PAINT seems not working Pin
JohnCz31-Jan-05 14:12
JohnCz31-Jan-05 14:12 
GeneralRe: WM_PAINT seems not working Pin
int01hh3-Feb-05 9:02
int01hh3-Feb-05 9:02 
GeneralList Control displays no Text Pin
RobertW10031-Jan-05 8:16
RobertW10031-Jan-05 8:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.