Sign in to follow this  

Unable To Load Dll (Custom Dll)

Recommended Posts

I'm trying to load a DLL using extern().  This is a known good DLL as I have this same project running on 3 systems (one Win7, two Win8) without issue.


For some reason I get the "Unable to load DLL" error on this 4th system.  At first I thought I might have some permissions / UAC issue, as that's bit me before on a new PC, but I disabled UAC, installed as administrator, ran as administrator, and even tried the XP compatibility mode to no avail.


The file path is OK, because I can copy and paste the path it says it couldn't load ("C:\Users\..\..\myDll.dll") into a Run... dialog such as "notepad [path]" and it'll pull it up.

Any ideas?  Clearly this has to do with file paths or permissions somehow but without more information than "unable to load" I'm having a hard time narrowing it down.


My next step is to dig up the Visual C++ solution for the DLL and run it in debug mode, but that's a lot of installation and setup that has a decent chance of ending in VC++ never getting called at all, which won't tell me much.


I'm also going to try a simple version of the load in a different project with an easy file path and see what that gets me.


Taking all suggestions here.



Share this post

Link to post
Share on other sites

This is almost certainly a dependency issue.  UAC won't really affect a DLL.  Basically, most all DLL's and executables rely on a number of secondary DLL's to run.  Many are system DLL's, but many are not, and if those DLL's that your DLL depends on aren't available on your system, then your DLL won't load.  Unfortunately, the operating system doesn't tell DAQFactory why it can't load the DLL, it just fails, so the message in DAQFactory is a bit less than helpful.  But the bottom line is this, if extern fails, its usually one of two things:


1) it can't find your dll.  Using the absolute path in extern() fixes this, or:

2) the system can't find a dependency for your dll.


To solve dependency issues, I recommend downloading the dependency walker program.  Just search for "dependency walker" or similar (if you search just for "depends", the name of the program, you get a bunch of links to the brand of underwear).  Run this program, then have it load your dll.  It will rather quickly show you which DLL's your DLL depends on that aren't installed on the system.  My guess is that its the C++ runtime libraries, which are not including with windows.  You'll want the redistributables for whatever version of visual studio you are using, which you can get off the microsoft site.

Share this post

Link to post
Share on other sites

Absolutely correct -- thanks!


C++ runtimes weren't my only problem, but they were the biggest one.


For the next person with this problem:  I got a bit of a red herring from the Dependency Walker because it complained of mismatched CPU types on modules.  Apparently you should use the x86 version of Dependency Walker when looking at a 32-bit DLL (even when on a 64-bit system), or this type of thing happens.


Thanks again for getting me out of DLL hell!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this