2

I want to call a function which is written in "C" DLL from node.js javascript. I am using "ffi" module in node.js and electron. The function which I want to call is "int FDColor_GetSWVersion(char* softwareVersion)". I am using the below code:

 var libm = ffi.Library(__dirname + "\\viewmodels\\FDColor.dll", {
      'FDColor_GetSWVersion': [ 'int', ['string' ] ]
    });

But I am getting the error "Dynamic Linking Error: Win32 error 126". Could anyone please help me out

Naveen Chandra Tiwari
  • 5,055
  • 3
  • 20
  • 26

1 Answers1

1

When you get "the specified module cannot be found", this refers to the DLL you tried to load or any of its dependencies.

You have given a full path to the ffi.Library function, but when FDColor.dll loads its dependencies it will probably use no path, which causes LoadLibrary to look first in the current-working-directory of the process and then in the directories of the PATH environment variable.

So,

  1. Use DependencyWalker (http://www.dependencywalker.com/) on FDColor.dll to see if it has any dependencies. The best way to do that is to call it from the same place as you call this script (giving the same path you pass to ffi.Library).

  2. For each DLL it would try to load, but is not found, you need to add the folder to the PATH environment variable of the environment that calls this script.

  3. You can check that you have done this right by repeating step 1 after setting PATH at the command prompt. DependencyWalker will now show that it can find those DLLs.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • It's displaying error "Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module." – Naveen Chandra Tiwari Jul 01 '16 at 13:46
  • Great -- move on to step 2 :) -- it might help to show some screenshots of what is happening in your question. – Lou Franco Jul 01 '16 at 13:48
  • It was working when I was creating sample. Now I have implemented this into my real project and its throwing the error "Uncaught Error: Dynamic Linking Error: Win32 error 193". Could you please help me out here? – Naveen Chandra Tiwari Aug 09 '16 at 06:58
  • You should make a new question – Lou Franco Aug 09 '16 at 13:28
  • I have created.. Please check http://stackoverflow.com/questions/38843150/error-with-ffi-module-node-js-uncaught-error-dynamic-linking-error-win32-error – Naveen Chandra Tiwari Aug 09 '16 at 13:29