Search code examples
c#c++visual-studio-2010dllboost-thread

Program works only on some pc, DLL missing?


I wrote with VS10 the following projects:

  • a C# (.net 4.0) program which calls
  • a C++ unmanaged dll, which make use of boost::thread
  • a setup project which includes the C# executable, the C++ dll, the boost::thread dll and some other files. Moreover during the installation there is a check if the framework .net 4.0 is installed, and if not it will be downloaded.

The compilation (x64 for each of the three projects) is ok, and the program works on my pc (Windows 7 64bit). I tested the program on some other computers (all Windows 7 64bit) and I noted that:

  • in the ones with VS10 and Boost the program works
  • in the ones without VS10 and Boost the program gives an error in the C++ Dll

I think the problem is that some boost Dll is missing. Am I right? Or the problem could be related to VS?

edit:

I have to mention that the structure of the program is the following:

  • main form (C#) in which some parameters are set, then a backgroudworker calls
  • the C++ DLL which do its stuff and uses boost::thread
    • it does some computations
    • when it get some results, writes them on file
    • continue with its computations and so on
  • the main form has a filesystemwatcher which looks for the results file and do some stuff with the results.

Also, when I get the error, the main form correctly loads and the parameters could be set. The error happens when the backgroundworker starts his work (calling the C++ DLL).

So I'm quite sure that there is no problem with the framework installation.

Update:

It turns out that I forgot to include some DLLs in the setup project. Now, including them the error changed.

Now, at the same point as before (and on the same computers) I get another error:

BadImageFormatException: An attempt was made to load a program with an incorrect format

I read this article, but I have set x64 in both C# project and in C++ DLL and the setup project has as TargetPlatform x64. Any idea?


Solution

  • I finally found the solution!

    The C++ DLL needs the mpfr library for multiple precision floating point computations with correct rounding.

    I was including (shame on me!) the incorrect version of the library (x86) and this was the motivation for the error:

    BadImageFormatException: An attempt was made to load a program with an incorrect format

    Then in all the computers (three different computers!) in which the program was ok there were both (unlucky and misleading coincidence):

    • Boost and VS10 installed and
    • a x64 version of the library in a folder contained in the Path environment variable. So, in some way the program found the right version of the DLL.

    Including the right version of the library in the Setup Project fixed the problem. Thanks to Kamil Klimek, Stephane Rolland and Mr.C64 for their precious suggestions.