Ammar
Ammar

Reputation: 33

DLL in sub folder rather than in application folder

have created a dynamic python file (pyd) using VC++. Using cx_freeze, I have created an exe. In order for this program to work on other computers, I need to have a file msvcr100.dll in the applications folder. And I do get the desired output.

However the distribution license for Microsoft clearly states that the dll files should be in a sub folder within the application folder. The sub folder should be named "Microsoft.VC100.CRT". I have tried playing around with the settings in MS VC++ by changing the project properties. Its proving to be very tricky as the only thing I used MSVC++ was for my python program to use some c option and return some output which I can use again in my python program. I have played around with manifest files (embedding and without embedding), also set the Additional Libraries Directory in VC++

Any one got any ideas as to what I can do to make my pyd file look into the Microsoft.VC100.CRT.

Upvotes: 0

Views: 859

Answers (2)

Ammar
Ammar

Reputation: 33

The dynamic python file I had created was compiled using Visual C++ 2010. Hence in order for it to work, the MSVCR100.dll files were needed. However as I had also created an application (.exe) of my final program, it depended on MSVCR90.dll. As Microsoft insist that these dlls should be in a folder with a particular name, I couldn't just place these files in the application folder. Hence what I did was compiled the pyd file using Visual C++ 2008. Then added the MSVCR90.dll file along with the corresponding manifests and MSVCP90.dll and MSVCM90.dll files. This solved the problem.

My guess is that before my program in order to work needed two generations of C run time files. By compiling the pyd file using VC++2008, I effectively reduced that dependancy to one generation.

Upvotes: 0

WaffleSouffle
WaffleSouffle

Reputation: 3363

I'm not sure when in your script the DLL is loaded, but assuming it's delayed to the point you can do something about it, then you can have a go at loading the library yourself:

import os
import ctypes
try:
    here = os.path.dirname(__file__)
except NameError:
    here = os.getcwd()
dll = ctypes.CDLL(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll'))
del here

or with pywin32

import os
import win32api
try:
    dll = win32api.LoadLibrary('msvcr100.dll') #Never hurts to try
except win32api.error:
    try:
        here = os.path.dirname(__file__)
    except NameError:
        here = os.getcwd()
    #Just to prove messing with PATH does something.
    os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(here, 'Microsoft.VC100.CRT')
    dll = win32api.LoadLibrary('msvcr100.dll') #Give it another crank of the handle.
    #Or alternatively without messing with PATH
    dll = win32api.LoadLibrary(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll')) #Give it another alternative crank of the handle.
    del here

Upvotes: 1

Related Questions