none
switching the dll file used in a dllimport RRS feed

  • Question

  • Hello all,

    I am using [dllimport  to import a delphi 7 DLL file into my project, but i have hit a point where i need to use different dll files based on the users input into the application.

    for example, if the user was to press button 1, then dll "dllfile1.dll" would be loaded, button 2 would load "dllfile2.dll" etc. there are around 15 dll files that could potentially be used and all have the same entry method name.

    Can anyone think of a good way around this programmatically without me putting in a [dllimport command for each file and then having to update the software each time i need to add / remove one of the dll files to be used? Also i guess with doing it this way i couldnt just put all the imports into the same class as the entry methods are the same?

     

     

    • Moved by Figo Fei Thursday, October 21, 2010 9:20 AM (From:Visual C# Language)
    Tuesday, October 19, 2010 10:30 AM

Answers

  • A little change in my ApiFactory could be made to take the dll to load as parameter.

    A really little change, in fact: remove the local variable declaration of dllName and make a dllName optional parameter instead. Et voilà, now it can use a Dll attribute or its parameter. You can call CreateNativeApi as many times as you need.

    • Marked as answer by Graham_M Friday, October 22, 2010 8:20 AM
    Tuesday, October 19, 2010 11:36 AM

All replies

  • A little change in my ApiFactory could be made to take the dll to load as parameter.

    A really little change, in fact: remove the local variable declaration of dllName and make a dllName optional parameter instead. Et voilà, now it can use a Dll attribute or its parameter. You can call CreateNativeApi as many times as you need.

    • Marked as answer by Graham_M Friday, October 22, 2010 8:20 AM
    Tuesday, October 19, 2010 11:36 AM
  • If all share the same function signatures you could make a generic wrapper by just calling LoadLibrary your self then use GetProcAddress and GetDelegateForFunctionPointer to get delegates for the functions.
    Tuesday, October 19, 2010 7:33 PM
  • Hi Graham_M,

    It is long time since the last reply, did you get useful information from above suggestions, or you still have any concerns about this issue? please feel free to let us know.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, October 22, 2010 4:58 AM
  • Hi, the API factory appears to have helped in a certain respect, apologies for not closign this up sooner, been super busy :)

     

    i had a complete mental block for a while and struggled to impliment it, and it is wokring to a certain degree, i added a simple procedure to my delphi dll to take an integer, add 100 and then return that value. I managed to get that working but i am having issues when working with the other procedures from delphi, the ones involving a TDLLCallBack and a Variant type.

     

    But yeah, i think the APICentre helped me!

     

    Cheers all

    Friday, October 22, 2010 8:19 AM