C++ Excel Add-in loading error: XLL file is loaded by Excel as text file

3k views Asked by At

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?

If click 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
1

There are 1 answers

0
Malick On BEST ANSWER

To summarize, the error code This program cannot be run in DOS mode. is usually related to one of the following issues:

  1. The XLL is built with the /MD flag, but end-users do not have the required CRT DLLs.

  2. The XLL is compiled with the wrong platform; e.g. Platform x64 being used for building your XLL, and then it is loaded in 32-bit Excel (or vice-versa).

  3. There is a missing external DLL dependency.

  4. There is an external DLL dependency which has been built with the /MD flag (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 /MT flag (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.