You are welcome to participate in the XSharp newsgroups and forum.

When posting to the newsgroups and forums we ask you kindly to follow the rules that you can find here: https://www.xsharp.info/faq/39-xsharp-news-server-rules

dynamic dll import (with classmate)

More
1 week 2 days ago #1 by Stefan Hirsch
Stefan Hirsch created the topic: dynamic dll import (with classmate)
Hi all,

in VO I loaded a dll dynamically like this:
hDllInst := cmLoadLibrary(sDllFileName)
IF hDllInst == NULL_PTR
   RETURN FALSE
ENDIF
pDllName := cmGetProcAddress(hDllInst,"_DLLNAME")
IF pDllName == NULL_PTR
   RETURN FALSE
ENDIF
....

Now that all my framework, plugin dlls and applications are VOXPorted I try to load the plugin dlls. cmLoadLibrary seems to work since it returns a pointer != NULL. But cmGetProcAddress returns NULL_PTR. How can a load the function pointers? Or is there any other simple approach to load dlls. I have dozens of plugin dlls. So I try to avoid refactoring all of them (for now).

Regards,
Stefan

Please Log in to join the conversation.

More
1 week 2 days ago #2 by Stefan Hirsch
Stefan Hirsch replied the topic: dynamic dll import (with classmate)
Hi all,

I think I have found a solution:
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

Please Log in to join the conversation.

More
1 week 2 days ago #3 by Chris Pyrgas
Chris Pyrgas replied the topic: dynamic dll import (with classmate)
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

XSharp Development Team
chris(at)xsharp.eu

Please Log in to join the conversation.