Can't find unmanaged DLL using DLLImport RRS feed

  • Question

  • Folder Structure

    Above is my folder structure. I have a Cordova app and a Windows Runtime Component - IBscanUltimate. The include folder has the C# code calling into the unmanaged IBscanUltimate.dll. Class1.cs is like this:

    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;

    The IBScanUltimateApi.cs & _IBSU_GetSDKVersion look something like this:

    internal partial class 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;

    IBScanUltimate.dll Properties

    I have placed the DLL in many locations to see if it'll get picked up and they all have the above properties. But when I try to run my app, it says unable to locate the IBScanUltimate.DLL

    This is how the output is coming:



    I am not sure what is it that I am doing wrong and why the DLLImport cannot find my dll. Thank you for your help.

    Exact error is:

    System.DllNotFoundException: Unable to load DLL 'IBScanUltimate.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    Update 1: I have come across 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)
        //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:

    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?

    • Moved by Breeze Liu Wednesday, March 15, 2017 7:35 AM cordova
    • Edited by nomana123 Thursday, March 16, 2017 7:06 PM More info
    Tuesday, March 14, 2017 3:15 PM

All replies

  • Hi nomana123,

    Welcome to the Developing Universal Windows apps forum! We are focusing on developing Universal Windows apps issue, and your issue is more relative to Cordova, I will move this thread to corresponding forum for a professional answer.

    Best regards,

    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, March 15, 2017 7:38 AM
  • Hi,

    From the screenshots, it doesn't look like a Cordova Application. Which Template are you using?

    Best Regards,

    Elvis Xia

    Wednesday, March 15, 2017 8:12 AM
  • Hi Elvis,

          This is a cordova project.

    Wednesday, March 15, 2017 11:43 AM
  • My app uses the same libraries, but in VB.NET.

    There are two versions of these libraries, 32 and 64bit. Check which DLL you are using.

    In VB.NET, I too had to use the SetDllDirectory API to load it from my project's DLL folder.

    Thursday, June 1, 2017 2:58 AM