locked
LoadPackageLibrary cause ERROR_BAD_EXE_FORMAT

    Question

  • Hi Experts,

    I am debugging my win8 app in a 64 bit Windows 8. My debug configuration is set to win 32.

    And in my code I am trying to load a 32bit dll like :

    dllHandle= LoadPackagedLibrary(L"XXXwin32.dll", NULL);
    if (!DllHandle) {
       DWORD error = GetLastError();
       return false;
    }

    In this code I always get Error_bad_exe_format. I am wondering that my build configuration is already set to win32 why loading a 32bit dll still cause this error?

    BTW, what I can see is the WWAHost.exe running this programe during my debugging is using 64bit version under c:\windows\SysWOW64, is this be the root cause?

    Tuesday, March 05, 2013 3:01 AM

Answers

  • WWAHOST.exe that is launched from c:\windows\syswow64 directory is actually the 32 bit executable. You should notice a *32 next to the executable name in the details view of Task manager.

    As far as why the image/dll is not getting loaded, try using dumpbin.exe to verify if your application and the library you are trying to load are compatible with each other.

    For example, when you run the "VS2012 x64 Native Tools Command Prompt" and run:

    dumpbin /headers c:\windows\system32\wwahost.exe, you will notice "(PE32+)" which means it is 64 bit executable. :

    If you run: dumpbin /headers c:\windows\syswow64\wwahost.exe, you will notice "(PE32)" which means it is a 32 bit executable.

    Try running dumpbin on your executable and library and hopefully that should help you.

    Regards,

    Prashant.

    • Marked as answer by Jesse Jiang Monday, March 11, 2013 2:24 AM
    Tuesday, March 05, 2013 11:04 PM
    Moderator