Note: I know how to solve this. I am writing this question to understand WHY it happens.
Ok, so, I am getting this error C2440 'return': cannot convert from 'const IMAGE_DOS_HEADER *' to 'const PIMAGE_DOS_HEADER'
. Can anyone tell me why?
The thing here is that, as you probably know, PIMAGE_DOS_HEADER
is defined as typedef IMAGE_DOS_HEADER *PIMAGE_DOS_HEADER
so they are basically the same thing.
Here's a simple code that gives that error:
class TestClass
{
public:
const PIMAGE_DOS_HEADER get_header() const
{
return &hdr;
}
IMAGE_DOS_HEADER hdr;
};
If I remove the const
qualifier from the function (so it becomes const PIMAGE_DOS_HEADER get_header()
) or cast the return to PIMAGE_DOS_HEADER
then the error goes away. What I dont understand is why it is even happening on the first place given that PIMAGE_DOS_HEADER
is IMAGE_DOS_HEADER*
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (relative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
LONG e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;