Thread: Help me with this

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Help me with this

    Hello,

    I am not very good at C. Below is a code snippet I found on the net. I couldnt understand the line "pDosHeader = (PIMAGE_DOS_HEADER) lpFileBase;"
    What kind of a usage is it?
    Could anyone explain that line?
    Thanks.
    Code:
    void SomeFunction(SomeParameters)
    ;local variables
    -------------------
    PIMAGE_DOS_HEADER pDosHeader;
    LPVOID lpFileBase;
    
    .....
    .....
    
    lpFileBase = MapViewOfFile (hFileMapping, FILE_MAP_READ, 0, 0, 0);
    
    pDosHeader = (PIMAGE_DOS_HEADER) lpFileBase;
    
    if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
       {
           fprintf (stderr, "DOS header missing\n");
           UnmapViewOfFile (lpFileBase);
       }
    ....
    ....
    
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is a cast to convert a pointer of type LPVOID (lpFileBase) to PIMAGE_DOS_HEADER.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed