Results 1 to 5 of 5

Thread: Dynamically Reference Dll

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    34

    Post

    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

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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.

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    just use late binding. You can specify the object at runtime

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    34
    How does late binding work?

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    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
  •  



Click Here to Expand Forum to Full Width