I’m trying to load a DLL with LoadLibrary
, get an export using GetProcAddress
and call it.
(This is basicaly the same problem as in Calling functions exported by Dlls from Silver)
The code looks something like:
var hSilverDLL1 = LoadLibrary("SilverDLL1.dll")
var pFoo = GetProcAddress(hSilverDLL1, "_Foo@0");
var pFoo2 = pFoo as Func<Bool>
This fails with:
error E559: Cannot safely cast "FARPROC!" to "Func<Bool>" did you mean to use "as!"?
error E129: Cannot cast from "FARPROC!" to "Func<Bool>!"
Using as!
doesn’t help. The first error disappears but the second remains. Trying to pass through LPVOID
like this:
var pFoo = GetProcAddress(hSilverDLL1, "_Foo@0");
var pFoo2 = pFoo as! rtl.LPVOID
var pFoo3 = pFoo2 as! Func<Bool>
doesn’t work either:
error E129: Cannot cast from "LPVOID!" to "Func<Bool>!"
(Using as
rather than as!
gives even more errors. like in the first excerpt.)
The suggestion is the post I linked above doesn’t work for me. I can’t statically linked to the DLL. I need to load it at runtime and discover its exports at runtime.
Am I missing some obvious way to perform this cast?
(Using Elements 10.0.0.2255 on VS 2015 on Windows 10 x64, compiling x86 binaries.)