Click here to Skip to main content
15,888,020 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sequel encode? Pin
User 127829-Aug-04 10:35
User 127829-Aug-04 10:35 
GeneralRe: Sequel encode? Pin
mcgahanfl9-Aug-04 10:48
mcgahanfl9-Aug-04 10:48 
GeneralRe: Sequel encode? Pin
Stlan9-Aug-04 21:17
Stlan9-Aug-04 21:17 
GeneralRe: Sequel encode? Pin
mcgahanfl10-Aug-04 3:33
mcgahanfl10-Aug-04 3:33 
GeneralSimple DLL calling another DLL Pin
george330279-Aug-04 8:35
george330279-Aug-04 8:35 
GeneralRe: Simple DLL calling another DLL Pin
David Crow9-Aug-04 9:10
David Crow9-Aug-04 9:10 
GeneralRe: Simple DLL calling another DLL Pin
george330279-Aug-04 9:59
george330279-Aug-04 9:59 
GeneralRe: Simple DLL calling another DLL Pin
Antti Keskinen9-Aug-04 21:07
Antti Keskinen9-Aug-04 21:07 
Let me recompose the statement in a bit different manner..

You have program, call it Proggy, for now. Proggy loads only the second DLL, and uses GetProcAddress to get the exported function. When this exported function is called, the second DLL loads the first DLL in order to retrieve the required constant. Then the second DLL returns this constant to Proggy.

Is this logic correct ? If so, the steps to implement it are as follows:
1. Create the first DLL. It has a function funcXYZ that is exported and returns the constant.
2. Create the second DLL. It has a function func123 that is also exported, and returns a number.
3. The function inside the second DLL uses LoadLibrary to load the first DLL, and then GetProcAddress to obtain access to the function exported by the first DLL.
4. This function-pointer is used to call the exported function.
5. As you now have the number, you can use FreeLibrary to unload the first DLL. At this point, the function pointer becomes invalid.
6. Return the number from the second DLL's exported function just like you'd return any other number. See here, that in the second DLL's function, you need to create a local variable that will hold a copy of the constant delivered from the first DLL.

Here's a code example of the first DLL's function:
__declspec(dllexport) int ReturnConstant(void)
{
    return TheConstant;
}
Here is the function in the second DLL:
__declspec(dllexport) int GetNumber(void)
{
    // Load the first DLL
    HMODULE hMod = LoadLibrary("Number1.DLL");<DIV>

    // Get the procedure address
    int (*ptrFunc)(void) = (int (*)(void)) GetProcAddress(hMod, "ReturnConstant");<DIV>

    // Call the function
    const int theConstant = ptrFunc();<DIV>

    // Free the DLL
    FreeLibrary(hMod);
    ptrFunc = NULL;<DIV>

    // Use the constant here, or return it directly
    return theConstant;
}
Note that I've used a direct pointer-to-function declaration with GetProcAddress. It might be easier for you to use a typedef to declare the type first. See MSDN for an example of how typedef is used to declare pointer-to-function types.

Note also that I've used Microsoft Visual C++ to declare the exported functions. The __declspec identifier is not available in Borland C++, you must use some other keyword, like the __export.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Simple DLL calling another DLL Pin
george3302722-Aug-04 12:21
george3302722-Aug-04 12:21 
GeneralRe: Simple DLL calling another DLL Pin
Antti Keskinen22-Aug-04 20:41
Antti Keskinen22-Aug-04 20:41 
GeneralRe: Simple DLL calling another DLL Pin
george3302724-Aug-04 7:15
george3302724-Aug-04 7:15 
GeneralRe: Simple DLL calling another DLL Pin
Antti Keskinen24-Aug-04 7:33
Antti Keskinen24-Aug-04 7:33 
GeneralRe: Simple DLL calling another DLL Pin
george3302720-Sep-04 13:28
george3302720-Sep-04 13:28 
GeneralNTFS extended file attributes in C++ Pin
gokings9-Aug-04 8:25
gokings9-Aug-04 8:25 
GeneralRe: NTFS extended file attributes in C++ Pin
David Crow9-Aug-04 9:28
David Crow9-Aug-04 9:28 
GeneralRe: NTFS extended file attributes in C++ Pin
Toby Opferman9-Aug-04 11:57
Toby Opferman9-Aug-04 11:57 
GeneralRe: NTFS extended file attributes in C++ Pin
gokings9-Aug-04 20:46
gokings9-Aug-04 20:46 
GeneralGet the program folder Pin
Larsson9-Aug-04 8:20
Larsson9-Aug-04 8:20 
GeneralRe: Get the program folder Pin
OBRon9-Aug-04 8:28
OBRon9-Aug-04 8:28 
GeneralRe: Get the program folder Pin
Larsson9-Aug-04 8:30
Larsson9-Aug-04 8:30 
GeneralRe: Get the program folder Pin
Tom Wright9-Aug-04 10:23
Tom Wright9-Aug-04 10:23 
GeneralRe: Get the program folder Pin
Larsson9-Aug-04 11:03
Larsson9-Aug-04 11:03 
GeneralRe: Get the program folder Pin
Tom Wright9-Aug-04 12:12
Tom Wright9-Aug-04 12:12 
GeneralRe: Get the program folder Pin
Toby Opferman9-Aug-04 11:44
Toby Opferman9-Aug-04 11:44 
GeneralRe: Get the program folder Pin
PJ Arends9-Aug-04 16:05
professionalPJ Arends9-Aug-04 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.