Shoutbox

[VB] Runtime loading dll - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [VB] Runtime loading dll (/showthread.php?tid=30072)

[VB] Runtime loading dll by J-Thread on 08-17-2004 at 01:03 PM

I have searched the whole internet (especially the msdn documentation) but I haven't found what I am looking for.
I am making something in VB.NET, and I want to use functions of dll's. Of course it is possible by adding the references in design mode, but that is not what I want.

It's just like something patchou did in msgplus (but I think he did it with C++). The program reads the register, reads a string with the namespace of the dll, and loads it. I tried to use:

code:
Dim object = System.Activator.CreateInstance("dllName.Classname", "URIToAssembly")
but that didn't work... Anyone who knows how to do it? (if you know how to do it in VB6, that's good also..)
RE: [VB] Runtime loading dll by RaceProUK on 08-17-2004 at 09:47 PM

I don't know about VB.NET, but to use DLL functions in VB6:

code:
Declare Function <fn-name> Lib "<lib>" Alias "<realname>" (<args>) As <type>
For example, RegOpenKeyEx:
code:
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

RE: [VB] Runtime loading dll by J-Thread on 08-18-2004 at 08:06 AM

Yes I know that, that's not the problem. But that will not work with VB dll's because they can't just share functions (unfortunatly). So that works with C++ dll's only. So I think I have to write my dll's in C++...


RE: [VB] Runtime loading dll by RaceProUK on 08-18-2004 at 08:48 AM

Vb DLL's can share functions (how do you think Plus calls VB plugins?): you just have to regsvr them.


RE: [VB] Runtime loading dll by J-Thread on 08-18-2004 at 08:53 AM

Yes of course they can, but (I think) not as C++ can. If you share functions with VB you can't use

code:
Declare Function <fn-name> Lib "<lib>" Alias "<realname>" (<args>) As <type>
can you? At least that's what I think... Correct me if I'm wrong. If you make dll's with VB you have to add them to the references and define an object like
code:
dim dll as new dllname.classname
And I think in VB it isn't possible to do that runtime. And if it is, I want to know how. That's my question.
RE: [VB] Runtime loading dll by RaceProUK on 08-18-2004 at 10:18 AM

Take a look at LoadLibrary() and related functions in the API.


RE: [VB] Runtime loading dll by J-Thread on 08-18-2004 at 08:03 PM

Yes thank you, i think that is what i was looking for! I haven't found a good tutorial about how to work with it, but it's a start. I'm going to test with it!


RE: [VB] Runtime loading dll by J-Thread on 08-19-2004 at 09:44 AM

YEAH! I got it. Not with loadlibrary (that's only for unmanged dll's), but like this:

code:
Dim hDLL As System.Reflection.Assembly
Dim hTyp As Type
Dim hMod As System.Reflection.MethodInfo
Dim obj As Object

hDLL = System.Reflection.Assembly.LoadFrom("MyVB.dll")   ' dll in Application.StartupPath or use full path
hTyp = hDLL.GetType("MyVB.MyVB")    ' Full class name ;)
obj = Activator.CreateInstance(hTyp)

' The class is active ... now let's call its methods

hMod = hTyp.GetMethod("MyFunc")
Dim args(0) As Object     ' Matching number of parameters
args(0) = 1
Msgbox("Returned value : " & hMod.Invoke(obj, args))

Read the whole thread about it here

I'm wondering why it's so hard to find this...