I'm looking for a command in windows cmd to tell me if a certain dll file is 32 bit or 64 bit
Is there something like this in windows ?
After you open the binary file in Notepad, use the Find option to look for the 1st occurrence of the word PE . The letter that follows the PE header tells you if the file is 32-bit or 64-bit. 32-bit (x86) programs would have PE L as the header. 64-bit (x64) programs would have PE d† as the header.
Solution 2 If possible create a separate 32 bits application that uses the 32 bit dll and call that using Process. Start()[^] from your 64 bits application. There are other ways like using named pipes for inter-process communincation, but they are quite complex to implement.
Press Ctrl + Shift + Esc to open up Task Manager. If you see the simple Task Manager interface, click on More details to see the full version. Once you see the full version of Task Manager, select the Detail tab from the horizontal menu at the top.
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
If you have installed 7zip :
"C:\Program Files\7-Zip\7z.exe" l "my-program.exe" | findstr CPU
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With