Search code examples
visual-studio-2010ironpythondllimportmanaged-c++dll

load c++ dll in ironpython


I have an ironpython app that uses dlls. Some of the dlls written in c#, and one is in managed c++. The app works fine on my host, and on any host that includes visual studio (2010) installation.

When I tried to run this app on hosts without vs, It failed. After some checking I discovered that ironpython cannot load the c++ dll. After installing vs - the app runs fine.

I narrowed it down: the dll can be uploaded after the installation of: -Microsoft application error reporting -VC 9.0 Runtime(x86) -VC 10.0 Runtime(x86) -Microsoft visual studio macro tools

I tried to install Microsoft Visual C++ 2010 Redistributable Package http://www.microsoft.com/download/en/details.aspx?id=5555 and it didn't do the trick.

  1. Why? what exactly happens in installation of vs, that doesn't occur when I install Microsoft Visual C++ 2010 Redistributable Package component?
  2. How can I monitor errors that arise when loading dlls with ipy?

Thank you!


Solution

  • The DLL that is written in managed C++ uses a DLL for its standard libraries. You can change it to static libraries. Follow these steps

    1. Open your project properties in Visual Studio (right click on the project)
    2. Click you way to Configuration Properties > C++ > Code Generation
    3. On the right, find Runtime Library and select Multi-Threaded Debug (/MTd)
    4. Do the same for the Release build, but this time select Multi-Threaded (/MT)
    5. Rebuild all

    As for your specific questions :

    1. The redistribuable installer will copy the DLL in the system path. Visual Studio will do the same thing. So if it doesn't work, make shure that you have the 32 or 64 bit binaries (same as your code, not the platform you are running). +If you are running from a console, close it and start a new one to get the updated path.

    2. Use Dependency Walker. Loading your DLL will show you what it is looking for, it should be enough. To monitor its runtime execution, load IronPython. In the "Profile" menu, select "Start Profiling" and provide a command line that will reproduce your problem.