Windows command to tell whether a .dll file is 32 bit or 64 bit?

You can use the dbghelp library to obtain the image headers. Then you can read the information you need out of the FileHeader.

Here's some sample code. Please forgive the rather lame error handling. I just knocked it up quickly to illustrate, and I'm not even remotely fluent in C++.

#include <Windows.h>
#include <Dbghelp.h>

#include <string>
#include <iostream>

using namespace std;

bool GetImageFileHeaders(wstring fileName, IMAGE_NT_HEADERS &headers)
{
    HANDLE fileHandle = CreateFile(
        fileName.c_str(),
        GENERIC_READ,
        FILE_SHARE_READ,
        nullptr,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        0
    );
    if (fileHandle == INVALID_HANDLE_VALUE)
        return false;

    HANDLE imageHandle = CreateFileMapping(
        fileHandle,
        nullptr,
        PAGE_READONLY,
        0,
        0,
        nullptr
    );
    if (imageHandle == 0)
    {
        CloseHandle(fileHandle);
        return false;
    }

    void *imagePtr = MapViewOfFile(
        imageHandle,
        FILE_MAP_READ,
        0, 
        0,
        0
    );
    if (imagePtr == nullptr)
    {
        CloseHandle(imageHandle);
        CloseHandle(fileHandle);
        return false;
    }
    
    PIMAGE_NT_HEADERS headersPtr = ImageNtHeader(imagePtr);
    if (headersPtr == nullptr)
    {
        UnmapViewOfFile(imagePtr);
        CloseHandle(imageHandle);
        CloseHandle(fileHandle);
        return false;
    }

    headers = *headersPtr;

    UnmapViewOfFile(imagePtr);
    CloseHandle(imageHandle);
    CloseHandle(fileHandle);

    return true;
}

int main(int argc, char* argv[])
{
    IMAGE_NT_HEADERS headers;
    if (GetImageFileHeaders(L"C:\\windows\\system32\\user32.dll", headers))
    {
        if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_I386)
            cout << "x86";
        else if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_IA64)
            cout << "IA64";
        else if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64)
            cout << "x64";
        else
            cout << "Machine not recognised";
    }
    return 0;
}

To link this you need to add dbghelp.lib to the additional dependencies of your project. To learn more about the details behind this, refer to the MSDN documentation for the various API calls that are used.


If you have installed 7zip :

"C:\Program Files\7-Zip\7z.exe" l "my-program.exe" | findstr CPU

DUMPBIN is included with Visual C++ and can provide this information with the /HEADERS switch.

Example output from a 32-bit image:

FILE HEADER VALUES
     14C machine (i386)
       6 number of sections
306F7A22 time date stamp Sun Oct 01 22:35:30 1995
       0 file pointer to symbol table
     1D1 number of symbols
      E0 size of optional header
     302 characteristics
            Executable
            32 bit word machine
            Debug information stripped