none
Using native dll through wrapper classes in a C# console application RRS feed

  • Question

  • I have a native DLL and my C# console application access it through a C# wrapper "class library". The files I have are as follows:

     * native.dll

     * wrapper.dll (c#) consuming classes of native.dll

     * C# console application consuming classes of wrapper.dll

    The compilation in VS2005 is ok but when I run the c# console app, I get an error: Unable to load DLL 'native.dll' : The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    I have already placed all the 3 dll files in a same folder. Can anyone advise what is wrong here?

    Thanks in advance.

    PS.I only have the source codes to the console app.
    Thursday, July 31, 2008 2:21 AM

Answers

  • The error could also be throw because native.dll has a dependence on another dll.  There is a program called dependence walker that you can use to check out any dependences native.dll have.  You could also maybe putting in the exact path to native.dll in your dllimport attributes to test.  Also p/invoke is short for platform invoke which is the .net services for interop with native code.

    http://dependencywalker.com/


    Platform Invoke
    http://msdn.microsoft.com/en-us/library/aa288468.aspx
    • Edited by AbdElRaheim Thursday, July 31, 2008 7:00 AM spelling
    • Marked as answer by ameico Thursday, July 31, 2008 7:14 AM
    Thursday, July 31, 2008 6:59 AM

All replies

  • I guess you are using P/Invoke to use this native assembly.  Make sure native.dll is in the same folder or in the windows or system 32 folders. 

    Dynamic-Link Library Search Order
    http://msdn.microsoft.com/en-us/library/ms682586.aspx

    If you don't know the path to native.dll until runtime you can check out Junfeng Zhang blog entry on how to do dynamic PInvoke.
    http://blogs.msdn.com/junfeng/archive/2004/07/14/181932.aspx
    Thursday, July 31, 2008 5:48 AM
  • I've put it in the windows/ system32 folder but the error remains.

    I'm not using the P/Invoke add-on in VS though. I see that the codes in wrapper.dll is using DllImport['native.dll'].... And what I did is just add wrapper.dll as reference into my C# console application and call the native functions from there. Compiles fine but to run the app, it still needs the native.dll, which it can't find.
    Thursday, July 31, 2008 6:01 AM
  • The error could also be throw because native.dll has a dependence on another dll.  There is a program called dependence walker that you can use to check out any dependences native.dll have.  You could also maybe putting in the exact path to native.dll in your dllimport attributes to test.  Also p/invoke is short for platform invoke which is the .net services for interop with native code.

    http://dependencywalker.com/


    Platform Invoke
    http://msdn.microsoft.com/en-us/library/aa288468.aspx
    • Edited by AbdElRaheim Thursday, July 31, 2008 7:00 AM spelling
    • Marked as answer by ameico Thursday, July 31, 2008 7:14 AM
    Thursday, July 31, 2008 6:59 AM
  • Yes, I got it working now. Indeed the native.dll has dependencies on a few other dll as described by dependencywalker. I moved all the dll into the  folder and it works fine now.

    Thanks a lot, AbdElRaheim.
    Thursday, July 31, 2008 7:14 AM