[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::visualc

Title:Microsoft Visual C/C++
Moderator:PLUGH::needle
Created:Tue Mar 16 1993
Last Modified:Wed Jun 04 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1121
Total number of notes:4385

1083.0. "Calling a .DLL function in runtime" by MSAM03::CHENHAOHAN () Thu Feb 06 1997 03:53

    I need some help on this. How does one go about calling a .DLL function
    where during compile-time is not known (even the .DLL filename is not
    supplied) but is required to be executed when the user supplies its
    function-name, parameters and .DLL filename? Reason being, I am
    experimenting with compiler design and would appreciate it if someone
    could advise me on how to solve the above problem.
    
    Thanks in advance.
T.RTitleUserPersonal
Name
DateLines
1083.1METSYS::GOODWINPete Goodwin, DEC/EDI EngineeringThu Feb 06 1997 06:336
    LoadLibrary and GetProcAddr are what you're after.
    
    Use LoadLibrary to load the DLL by filename, then use GetProcAddr to
    get a function pointer to a named function.
    
    Pete
1083.2Thanks PeteMSAM00::CHENHAOHANWed Feb 12 1997 01:0631
    Thanks Pete for your help...
    Using the LoadLibrary to load the DLL sure works fine but to call a
    "yet-to-know" function in the .DLL using a function pointer with a N
    number of "yet-to-know" parameters is a bit of a problem. Correct me if
    I am wrong because you'll need to define a "template" of the function
    pointer (with the correct number of parameters to be passed-in) before
    you are able to call the function. Consider this scenario:
    
    I have an interpreter ABC (written in Visual C++) which accepts the 
    following source:-
    
    external function ExecuteMe(X As Integer, Y As Integer) As Boolean in
    library "TryMe.DLL".
    
    external function AnotherEg() As Void in library "TryMe.DLL".
    
    action main
    do x = ExecuteMe(1,2)
    and do AnotherEg()
    end.
    
    ... as expected, the ABC interpreter will call the functions in
    TryMe.DLL. The problem now lies in the fact that I need to declare a
    "template" of the function pointer for each of the "unknown" functions
    (unknown during compile time of the ABC interpreter) and call these
    functions during the execution of the program written specifically for
    ABC.
    
    Hope you can supply me with some sample code. Thanks again for your
    advice.