none
Using a structure declared in a DLL

    Question

  •  

    I have created a DLL (called AddOnFunctions.dll) which contains the following structure:

     

     Public Structure databaseResults

            Dim oneCompleted As Boolean

            Dim twoCompleted As Boolean

            Dim threeCompleted As Boolean

            Dim finalArray(,) As String

        End Structure

     

    The DLL also contains a function that returns this structure.

     

    I have created a program that uses the DLL mentioned. I have declared the function in the DLL using the following line:

     

    Public Declare Function searchDatabases Lib "AddOnFunctions" Alias "searchDatabases" (ByVal data As String) As databaseResults

     

    but the program does not recognise the databaseResults structure returned by the function, because it has been declared in the DLL and not the program calling the function.

     

    How can I declare the structure in my program using the actual structure in the DLL.

     

    I know there are other ways of importing DLL files into programs, however I want to be able to create different DLL files with the same name and function declarations and return values, but the actual functions will have different code and the structure could contain different values. When I come to deploy the program I will just need to copy the appropriate dll file and not have to recompile the whole program.

     

    All help appreciated!

    Tuesday, July 15, 2008 4:30 PM

Answers

  • I would suggest picking on another path using dynamic assembly loading and reflection.

    First you would create a class library called "common" that declares the databaseResults structure and an interface (ex. IDatabases) that declares a single method called "searchDatabases".
    Then I would create the AddOnFunctions class library, reference the common.dll and create a type that implements the IDatabases interface declared in common.

    When my main application starts I would search for the AddOnFunctions.dll file and once found I would load that Assembly and use reflection to search for any type that implements the IDatabases interface. When I find the type I create an instance and then I can call the searchDatabases method through the IDatabases interface and get the result. 

    This is basically the foundation for loading PlugIns (before the AddIns namespace came with .net 3.5). Using this solution you can change the loaded dll file without recompiling, you can even change the name for the loaded dll if your dll search pattern can find it.

    /Calle 

    Tuesday, July 15, 2008 5:06 PM

All replies

  • I would suggest picking on another path using dynamic assembly loading and reflection.

    First you would create a class library called "common" that declares the databaseResults structure and an interface (ex. IDatabases) that declares a single method called "searchDatabases".
    Then I would create the AddOnFunctions class library, reference the common.dll and create a type that implements the IDatabases interface declared in common.

    When my main application starts I would search for the AddOnFunctions.dll file and once found I would load that Assembly and use reflection to search for any type that implements the IDatabases interface. When I find the type I create an instance and then I can call the searchDatabases method through the IDatabases interface and get the result. 

    This is basically the foundation for loading PlugIns (before the AddIns namespace came with .net 3.5). Using this solution you can change the loaded dll file without recompiling, you can even change the name for the loaded dll if your dll search pattern can find it.

    /Calle 

    Tuesday, July 15, 2008 5:06 PM
  • Hi,

    Add a reference to the DLL file from the PROJECT menu.

    You will find it in the BIN/DEBUG or BIN/RELEASE folder of your other DLL project.

    Next if your STRUCTURE is in a MODULE you should have immediate access to it ( I think, I can't remember ).

    Otherwise if the STRUCTURE is in a CLASS you will need.>>

    Imports DLLProjectNameHere.whatever_CLASS_name_here

    at the top of your FORM.

    Where you replace DLLProjectNameHere as appropriate as well as the CLASS name as appropriate.

    In your FORM you could then say

    Dim dbr1 as New dataBaseResults




    Regards,

    John


    I have previously been, until recently, an MSP ( Microsoft Student Partner ).
    Wednesday, July 16, 2008 2:58 AM