Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
The unmanaged DLL is not being found

What I have tried:

I have a cordova project referencing a windows runtime component. This is how I am calling the method from JS

using System;
namespace IBscanUltimate
{
    public sealed class Class1
    {
        public static String getSDK()
        {
            IBscanUltimate.DLL.IBSU_SdkVersion a = new DLL.IBSU_SdkVersion();
            IBscanUltimate.DLL._IBSU_GetSDKVersion(ref a);
            return "SDKVersion: " + a;
        }
}
This is the DLLImport piece which seems to be unable to find the particular DLL:
internal partial class DLL
{
    [DllImport("IBScanUltimate.DLL")]
    private static extern int IBSU_GetSDKVersion(ref IBSU_SdkVersion pVerinfo);
    public static int _IBSU_GetSDKVersion(ref IBSU_SdkVersion pVerinfo)
    {
        int nRc = IBSU_STATUS_OK;
        nRc = IBSU_GetSDKVersion(ref pVerinfo);
        return nRc;
    }
}
Exact error is:
System.DllNotFoundException: Unable to load DLL 'IBScanUltimate.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have placed my DLL in my runtime component as a content file and set the Copy to output to Copy always.

Update 1: I have come across https://msdn.microsoft.com/en-us/library/windows/desktop/hh447159(v=vs.85).aspx This article is explaining that
LoadPackagedLibrary
function can be used to load the dll. I am not seeing any example on how to use this in C#.

Update 2: Specify the search path for DllImport in .NET Mentions that SetDllDirectory or AddDllDirectory can be used. He has a code snippet for SetDllDirectory, but the argument is string[] paths. How would I specify the relative argument?

Update 3:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
public static bool setPath(String path)
{
    //Windows.Storage.
    //return SetDllDirectory("ms-appx:///");
    return SetDllDirectory(path);
}


I tried calling the SetDllDirectory(path) method with various locations that my app should have access to but I am keep getting "false". Few examples that I have tried:
NativeMethods.setPath(Package.Current.InstalledLocation.Path.ToString());
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFolder folder = Windows.Storage.KnownFolders.MusicLibrary;


This is where my app is installed:
C:\Users\AAA\App\hello\platforms\windows\build\windows\Debug\x64\AppX
and I can see that my DLL is there. But still I'm getting the exception that DLL cannot be found. Do I have to put something on the manifest regarding this?
Posted
Updated 16-Mar-17 9:11am
v2
Comments
jekin77 15-Mar-17 11:27am    
check you working directory ! because your assembly 'IBScanUltimate.DLL' should be placed in working dir. (usually is a ../bin/debug or ..bin/release one)
Member 13060802 15-Mar-17 11:58am    
Yea, its there, but still it says cannot find it :(
jekin77 15-Mar-17 13:38pm    
maybe your IBScanUltimate.DLL depends from other DLL that could not be found ?!
check you project settings -> Debug options->Working directory

Member 13060802 15-Mar-17 14:11pm    
I have been given the DLL and some sample code showing how to use the DLL. That sample project is running fine, I'm trying to mimic that into my cordova app but I'm running into this problem.
RickZeeland 15-Mar-17 13:40pm    
Make sure you have the right version of the DLL, x86, x64, Debug or Release.
You can use Dependency Walker to see if the dll has missing references.
Good luck !

1 solution

Looks like you are in "dll hell". Your only friend is the good old Dependency Walker. Often this error is a syndrom that some other dlls like some run time dll are missing. Check out that your dll finds all needed dll. Watch out for red or rose dlls in the Dependeny Walker.

Is the behaviour different, when single step debugging?
Check after the setup, that the dll is where it should be on the target machine.

Tip: link your dll as static library. You get a fat but reliable dll
 
Share this answer
 
Comments
Member 13060802 16-Mar-17 15:26pm    
If I do link my dll is static library, would I be able to generate .winmd module? That's what I will need.
[no name] 17-Mar-17 0:41am    
Shouldn't you contact Integrated Biometrics for support?
For what it's worth... I suspect KarstenK is correct and that you need to install the Visual C++ Redistributable for whatever Visual Studio version the DLL was compiled with. You can avoid this by using a static linked DLL.

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
Member 13060802 17-Mar-17 9:56am    
Can you explain how to "Link dll as static library" please. Also how would I use it as a windows runtime component?
[no name] 17-Mar-17 16:42pm    
Did you search here on codeproject?
https://www.codeproject.com/Articles/85391/Microsoft-Visual-C-Static-and-Dynamic-Libraries
Member 13060802 20-Mar-17 13:14pm    
I ran a dumpbin on the DLL and i see the below DLL in the dumpbin:
WINUSB.DLL
mfc90.dll
MSVCR90.dll
KERNEL32.dll
USER32.dll
GDI32.dll
VERSION.dll
MSVCP90.dll
SETUPAPI.dll

I guess I'd like to check on each dll above separately to see if my windows runtime can pick it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900