Ricardo Paiva · May 6, 2016

Load a dll at run time

I am using java gateway imported/proxy classes and JG business service. I need to load a dll at run time.

I use System.loadLibrary/System.load when in java. I’ve tried $ZF(-3,” C:\Windows\System32\pteidlibj.dll”) and $ZF(-4,1,"C:\Windows\System32\pteidlibj.dll") but I’m getting <DYNAMIC LIBRARY LOAD> error.

How can I load a dll at run time using COS?

0 1,054
Discussion (5)3
Log in or sign up to continue

After this error you should look at cconsole.log, where you can find error code, why loading was failed.
Mostly there are two errors with loading dll in cache,  using 32bit dll instead of 64bit. And if this library has unsatisfied dependencies, in this case I'm using this tool to find such dependencies.

When running the following: $ZF(-4,1,"C:\Windows\System32\pteidlibj.dll"), I’m getting DYNAMIC LIBRARY LOAD and nothing is written to cconsloe.

If I use $ZF(-4,1,"pteidlibj.dll"), the error persists but I’m getting this on cconsole: (4584) 1 Error loading dll (c:\intersystems\ensemble\mgr\testing\pteidlibj.dll) is 126.

In my java code, I’m using: System.load("C:/Windows/System32/pteidlibj.dll"), dll is properly loaded. It’s exactly the same dll.

126 error means - The specified module could not be found.

So, you have dependency issue, so I recommend to use dependency tool which I suggested before, to find what you need.

I would like to add that $zf(-3) and $zf(-4,1) calls can only be used to load what we call a callout library. This is a specific DLL that properly exports functions during linking and  exposes them in a ZFENTRY table. You can find more material about the callout gateway in this part of the documentation:

If you want to work with a specific DLL that is not a callout library, you have to wrap the library, e.g. in a Java jar library or a callout DLL and then call out from Caché Object Script.

The project Evgeny mentioned may be of help as well.