xsharp.eu • dynamic dll import (with classmate)
Page 1 of 1

dynamic dll import (with classmate)

Posted: Thu Apr 12, 2018 10:24 am
by SHirsch
Hi all,

I think I have found a solution:

Code: Select all

VAR dll := System.Reflection.Assembly.LoadFile(sDll)
FOREACH t AS System.Type IN dll:GetExportedTypes()
  IF t:ToString():EndsWith("Functions")   //should start with name of dll ( -> check)
    FOREACH m AS System.Reflection.MethodInfo IN t:GetMethods()
      IF m:Name:ToUpper() == "_DLLTYPE"
        VAR n := (INT)m:Invoke(NULL, NULL) 
        ....
      ENDIF
    NEXT
  ENDIF
NEXT
Not the most elegant way but shows an approach.

Regards,
Stefan

dynamic dll import (with classmate)

Posted: Thu Apr 12, 2018 2:13 pm
by Chris
Hi Stefan,

The xxxLoadLibrary() functions can only be used to load standard windows dll files with functions, but in your case, now you are attempting to load .Net assemblies, which have a completely dirferent format and do not even have "real" functions, they only have classes and as you saw x# "functions" are only methods of a special class.

The correct way to use .Net dlls is exactly what you did, to use reflaction, also the VulcanLoadLibrary() runtime function does the same thing more or less. But it is better I think to use your own implementation as you have done it already, so you are in full control.

Chris