怎麼確定一個DLL檔案是32位的還是64位的
阿新 • • 發佈:2019-01-02
從PE檔案格式入手。檢查 IMAGE_FILE_HEADER 中的machine成員即可
int __stdcall CrnGetImageFileMachine(LPCSTR lpFileName)
{IMAGE_DOS_HEADER idh;
FILE *f = fopen(lpFileName, "rb");
fread(&idh, sizeof(idh), 1, f);
IMAGE_FILE_HEADER ifh;
fseek(f, idh.e_lfanew + 4, SEEK_SET);
fread(&ifh, sizeof(ifh), 1, f);
fclose(f);
return ifh.Machine;
}
{
// TODO: Add your control notification handler code here
int n = CrnGetImageFileMachine("D:\\W32N55.dll");
if (n == 0x014C)
MessageBox("x86");
else if (n == 0x0200)
MessageBox("IA64");
else if (n == 0x8664)
MessageBox("x64");
else MessageBox("未知型別");
}