dynamic dll import (with classmate)

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
SHirsch
Posts: 282
Joined: Tue Jan 30, 2018 8:23 am

dynamic dll import (with classmate)

Post 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
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

dynamic dll import (with classmate)

Post 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
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply