What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [VB] Runtime loading dll

[VB] Runtime loading dll
Author: Message:
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
O.P. Huh?  [VB] Runtime loading dll
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..)

This post was edited on 08-17-2004 at 01:04 PM by J-Thread.
08-17-2004 01:03 PM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [VB] Runtime loading dll
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

This post was edited on 08-17-2004 at 09:48 PM by RaceProUK.
[Image: spartaafk.png]
08-17-2004 09:47 PM
Profile PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
O.P. RE: [VB] Runtime loading dll
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++...
08-18-2004 08:06 AM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [VB] Runtime loading dll
Vb DLL's can share functions (how do you think Plus calls VB plugins?): you just have to regsvr them.
[Image: spartaafk.png]
08-18-2004 08:48 AM
Profile PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
O.P. RE: [VB] Runtime loading dll
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.
08-18-2004 08:53 AM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [VB] Runtime loading dll
Take a look at LoadLibrary() and related functions in the API.
[Image: spartaafk.png]
08-18-2004 10:18 AM
Profile PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
O.P. RE: [VB] Runtime loading dll
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!
08-18-2004 08:03 PM
Profile E-Mail PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
O.P. RE: [VB] Runtime loading dll
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...
08-19-2004 09:44 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On