Search code examples
winapinode-ffi

calling setDllDirectory using node ffi


I am using node ffi module to call native windows functions that are in my own dll. My dll depends on some other third party dlls that are in the same directory.

THe problem is that after loading the dll referred to me when calling

   var myfunc = ffi.Library("myLibrary", {"test":["string",["string"]]})

It cannot find the third party dlls that myLibrary depends on though they are in the same directory. I have tried to call setDllDirectory prior to this line by doing this:

  var setdl = ffi.Library("kernel32", {'SetDllDirectory':["bool",["string"]]})

and then calling setdl. But I get an error in the setdl line above itself:

 Uncaught Error: Dynamic Symbol Retrieval Error: Win32 error 127(…)

How can i fix this?


Solution

  • Error 127 is ERROR_PROC_NOT_FOUND ("The specified procedure could not be found").

    There are two versions of the SetDllDirectory() function:

    • SetDllDirectoryA for ANSI.
    • SetDllDirectoryW for Unicode.

    The DLL does not export a function actually named SetDllDirectory(), hence the error. It exports the two other functions instead.

    This information is stated in the documentation:

    image