|
-
May 2nd, 2000, 12:26 AM
#1
Thread Starter
Member
Is there any way to dynamically set a reference to a dll using vb code alone. The problem i have is that i want to write a prog that will interact will an variable amount of dll's, and so i want to set up the references dynamically depending on which dll's are going to be used
Any help will be greatly appreciated
Thanks
-
May 2nd, 2000, 12:48 AM
#2
Frenzied Member
It's quite Hard, it depends on the interfaces of the Dlls, If you can somehow control the interface to something that takes four long integers by value, Remember anything by reference is the same as passing it's pointer by value.
If so you can use the LoadLibrary API to get the dll into memory, GetProcAddress gets the address of a function (hModule should be the return value of loadlibrary), FreeLibrary releases the memory.
CallWindowProc can call a function by it's address as long as it has the set four long integer interface, the first parameter is the address of the function.
If you can't predict the interface then you're in trouble, If you can limit it to a few interfaces then you can set up a class module with a method for each interface you need to use, you can then modify the classes vtable and call the classes methods to call you're functions.
There's an article on vTable Modification at http://www.bstorage.com/nervenet/VTableModification.asp, but it's not easy.
-
May 2nd, 2000, 11:31 PM
#3
Guru
just use late binding. You can specify the object at runtime
-
May 3rd, 2000, 12:47 AM
#4
Thread Starter
Member
How does late binding work?
-
May 3rd, 2000, 12:57 PM
#5
Guru
Declare your variable as Object (as opposed to ADODB.Recordset, or some other specific object)
When you want to create a certain object, just put in a string variable
dim objMyObject as object
set objMyObject = createobject("ADODB.Recordset")
or you could use a string variable in place of a constant
The performance is much worse than explicitly declaring your objects, but you have the benefit of flexibility. You do not, however, have an easy way to tell what methods that the object supports. If you build your objects with a standard interface (set of properties and methods) you can interchange them at runtime easily. There was an article a few months back in VBPJ that discussed these concepts....
HTH
Tom
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|