

EXE files are binary, but you are you trying to display the raw binary data as-is, which will not work. You were on the right track thinking that you need to encode the binary data to hex before displaying it. Binary data is not displayable, but hex is.

Try this instead:

static const TCHAR Hex[] = TEXT("0123456789ABCDEF");

BOOL ReadInEXEFile(HWND hEdit, LPCTSTR pszFileName) 
{ 
    BOOL bSuccess = FALSE; 

    HANDLE hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 
    if (hFile != INVALID_HANDLE_VALUE) 
    { 
        DWORD dwFileSize = GetFileSize(hFile, NULL); 
        if (dwFileSize != INVALID_FILE_SIZE)
        { 
            LPTSTR pszFileText = (LPTSTR) LocalAlloc(LMEM_FIXED, ((dwFileSize * 3) + 1) * sizeof(TCHAR)); 
            if (pszFileText != NULL)
            {
                BYTE buffer[1024];
                DWORD dwOffset = 0;
                DWORD dwRead; 

                for (DWORD dwFilePos = 0; dwFilePos < dwFileSize; dwFilePos += dwRead)
                {
                    if (!ReadFile(hFile, buffer, sizeof(buffer), &dwRead, NULL)) 
                    {
                        CloseHandle(hFile);
                        return FALSE;
                    }

                    if (dwRead == 0)
                        break;

                    for (DWORD idx = 0; idx < dwRead; ++idx)
                    {
                        pszFileText[dwOffset++] = Hex[(buffer[idx] & 0xF0) >> 4];
                        pszFileText[dwOffset++] = Hex[buffer[idx] & 0x0F];
                        pszFileText[dwOffset++] = TEXT(' ');
                    }
                }

                pszFileText[dwOffset] = 0; // Add null terminator 

                bSuccess = SetWindowText(hEdit, pszFileText);
                LocalFree(pszFileText);
            } 
        } 

        CloseHandle(hFile); 
    } 

    return bSuccess; 
}

