Unable to load DLL in WPF C# application

2019-09-06 10:24发布

问题:

I get following error message (VS2010) when running in debug mode my C# WPF appliction:

"Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

The code where this error occurs is (see hDevEnum):

namespace Imperx.FLExGrabber
{
public class Enumerator:IEnumerator
 {
    private IntPtr hDevEnum;

    VCECLB_EnumData enumData;
    /// Default constructor

    public Enumerator()
    {
        enumData.cbSize = (UInt32)Marshal.SizeOf(enumData);

        // Open enumerator handle
        hDevEnum = NativeFunctions.VCECLB_EnumInit();  <<--- Error message here!!!
    }

    /// Destructor
    ~Enumerator()
    {
        NativeFunctions.VCECLB_EnumClose(hDevEnum);
    }

 }
}

From the existing project, which uses a windows form application, it runs perfectly. Now I need to transfer this solution into a WPF-application. Therefore I am using the same machine (Win7/64ibt) with the same VS2010. The platform target is X64.

Question: Where I need to add the VCECLB.dll file into my project? I can not add it under references and therefore I put it into the folder "...\bin\x64\Release" - but no success.

When I check the VCECLB.dll with dependency walker I get following:

Does the question marks means that those dll's are missing? If so, why I can run the windows form project with the same VCECLB.dll?

Does anybody know how I can solve this issue? Thanks in advance

回答1:

There are two common causes for such an error:

  1. The DLL that you are referring to is not on the DLL search path, or
  2. The DLL that you are referring to is found, but its dependencies cannot be found.

Resolve problem 1 by putting the DLL in the same directory as the executable. Resolve problem 2 by making sure that all dependencies are installed. Typically this involves deploying the MSVC runtime that the DLL depends upon.



回答2:

You can put your VCECLB.dll any where in your solution (in root for example by Drag & Drop)

Then, once you added the file, click right on your file, choose properties

In Advanced three:

  • Choose content in Build Action

  • And Always copy in Copy to output Directory

to get something like the follwing: