1

I have uploaded a project to Github to show the issue: https://github.com/EamonnLaffey/ctypes-test

I am using ctypes.open() to load a dll that simply calls a function of a dependent dll which prints a message.

Within the data folder of the extension are the two dlls. There is also an executable, test.exe calls the same function that the extension is trying to call to verify that it is working.

To get the path of the dll I set "unpack": true in extension's package.json and call the following in index.js:

var dllPath = Services.io.newURI(data.url('operations.dll'), null, null).QueryInterface(Ci.nsIFileURL).file.path;`

That will return a path such as

C:\Users\Eamonn\AppData\Local\Temp\1\f6ff0a5f-64b9-4953-a7a4-cb5b0a16c29c\exten‌​sions\@extension\data\operations.dll

When I manually go to the path I can see operations.dll, supporting.dll and test.exe as expected. Running test.exe will successfully load operations.dll which then loads supporting.dll.

However, when calling ctypes.open() on the path the following error is returned:

console.error: ctypes-test-ext:
  Message: Error: couldn't open library C:\Users\Eamonn\AppData\Local\Temp\1\f6ff0a5f-64b9-4953-a7a4-cb5b0a16c29c\exten‌​sions\@extension\data\operations.dll: error 126

When I load a dll that does not have any dependant dlls ctypes.open() works

Eamonn
  • 187
  • 2
  • 13
  • Can you make a xpi out of that addon. By typing `jpm xpi`. Then after that open that xpi with a zip software and then checked the install.rdf. You should see in there unpack:true, I think that's whats happening. You seem to be doing everything correct per the docs on custom native files - https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/ctypes.open – Noitidart May 06 '16 at 08:29
  • per http://stackoverflow.com/questions/14361992/dll-load-library-error-code-126 sysinternals' Process Monitor can be helpful in seeing what goes wrong. Perhaps it looks for the other DLL in a different location? – Nickolay May 08 '16 at 14:47
  • Looking at process monitor, Firefox is searching in C:\Program Files (x86)\Mozilla Firefox\ for dependent dlls which is what I though was happening. Is there anyway to get around this behavior? The only solution I can think of is using using a wrapper dll that takes in the extension path, then uses `LoadLibrary()` to dynamically load the actual dll I want to load. – Eamonn May 09 '16 at 06:42
  • This is interesting, now that I think about it, all dll's/so's/dylib's used via jsctypes i have seen in the past couple years have been standalone, and didnt depend on others. I'll try to look and see if I find someone using dependencies. – Noitidart May 09 '16 at 19:30
  • Currently I'm trying to create a wrapper dll and use `LoadLibrary`. However when I first call `SetCurrentDirectory` on the path where Firefox puts the dlls I get the error: `The filename, directory name, or volume label syntax is incorrect`. I believe I am getting this error because the path to the dlls contains an @ symbol. Could this be the underlying issue? How would I get around this. – Eamonn May 12 '16 at 08:38

0 Answers0