I’m building XLL add-ins for Excel, using C++ and XLW library.
It works fine on my PC, and on many others. But in some cases, when I drag the XLL into a new Excel window, this error shows up:
The file you are trying to open, ‘my_addin.xll’, is in a different
format than specified by the file extension. Verify that the file is
not corrupted and is from a trusted source before opening the file. Do
you want to open the file now?
yes, then Excel will open the XLL as a text file, showing something like this:
MZÿÿ¸@ Í!¸LÍ!This program cannot be run in DOS mode.
right at the first row. This is not expected to happen. What could be the reason for that?
This is the system configuration of all machines:
- Microsoft Windows 7 Professional 64-bit (operational system)
- Microsoft Excel 2010 32-bit
To summarize, the error code
This program cannot be run in DOS mode. is usually related to one of the following issues:
The XLL is built with the
/MDflag, but end-users do not have the required CRT DLLs.
The XLL is compiled with the wrong platform; e.g. Platform
x64being used for building your XLL, and then it is loaded in 32-bit Excel (or vice-versa).
There is a missing external DLL dependency.
There is an external DLL dependency which has been built with the
/MDflag (multithread-specific and DLL-specific version of the run-time library). In this case, there is no problem if end-users have the correct version of the CRT (the one that has been used to build the external DLL). Otherwise it is strongly recommended to rebuild your external DLL (if possible) with the
/MTflag (multithread, static version of the run-time library). Or even better, to statically link it to your XLL (using static .lib file as the output of the build of your third party component).
I believe the last one might be your case.