Click here to Skip to main content
15,922,650 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: RTTI/dynamic_cast Pin
John M. Drescher26-Jun-03 23:19
John M. Drescher26-Jun-03 23:19 
GeneralRe: RTTI/dynamic_cast Pin
Jim Crafton25-Jun-03 7:59
Jim Crafton25-Jun-03 7:59 
Generalimporting a DLL into a visual c++ 7 app Pin
si_6925-Jun-03 5:06
si_6925-Jun-03 5:06 
GeneralRe: importing a DLL into a visual c++ 7 app Pin
Peter Weyzen25-Jun-03 5:52
Peter Weyzen25-Jun-03 5:52 
GeneralRe: importing a DLL into a visual c++ 7 app Pin
si_6925-Jun-03 5:57
si_6925-Jun-03 5:57 
GeneralRe: importing a DLL into a visual c++ 7 app Pin
Peter Weyzen25-Jun-03 6:00
Peter Weyzen25-Jun-03 6:00 
GeneralRe: importing a DLL into a visual c++ 7 app Pin
si_6925-Jun-03 6:04
si_6925-Jun-03 6:04 
GeneralRe: importing a DLL into a visual c++ 7 app Pin
Peter Weyzen25-Jun-03 6:23
Peter Weyzen25-Jun-03 6:23 
So, there's 2 parts to this problem.
1) How to get access to the DLL and it's functions
2) How to integrate this into your program.

(1) access -- Get familiar with LoadLibrary and GetProcAddress. LoadLibrary will load the DLL into memory. GetProcAddress will probe the loaded DLL for it's entrypoints (functions). You should also understand "pointers to functions" and how to represent those in C++ code.

(A) Create a prototype for the function you want to call. This prototype declares a function pointer:
typedef int (FAR PASCAL *FunctionPrototypeName)();

note that the FAR PASCAL identifiers are defined by whoever wrote the DLL. This defines the "calling convention" used in the function. Get this info from whoever wrote the DLL.


(B) Declare storage for this pointer. Global variable is fine. [Consider wrapping all this stuff in a C++ class, i.e. represent the DLL as a class, compartmentalizing access to the DLL through the class. Abstract each entrypoint of the DLL into a C++ member function.]
FunctionPrototypeName   fp_function;

(C) In code, load the library:
HMODULE hDLL = LoadLibrary( _T("MyDLL.DLL" );

(D) Load the pointer to the function:
fp_function= (FunctionPrototypeName)GetProcAddress( hDLL, "ExportedFunctionName" );

(E) The function is now ready to be called:
int x = (*fp_function)()

(2) integration

As I mentioned in a note above. Represent the DLL as a C++ class. Each entry point in the DLL, should be represented by an member function in the C++ class.

-p

P.S. I can't guarantee my syntax is perfect. Compile errors may occur. Mileage may vary. Do not bend, spindle, or mutilate.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks

GeneralON_REGISTERED_MESSAGE Pin
Brian Delahunty25-Jun-03 4:32
Brian Delahunty25-Jun-03 4:32 
GeneralMMC question - need guru's help Pin
YaronNir25-Jun-03 4:23
YaronNir25-Jun-03 4:23 
QuestionHow to scan avalible wireless (802.11b) network in a MFC program? Pin
Robert Mao25-Jun-03 3:29
Robert Mao25-Jun-03 3:29 
AnswerRe: How to scan avalible wireless (802.11b) network in a MFC program? Pin
David Crow25-Jun-03 3:38
David Crow25-Jun-03 3:38 
GeneralRe: How to scan avalible wireless (802.11b) network in a MFC program? Pin
Robert Mao25-Jun-03 3:53
Robert Mao25-Jun-03 3:53 
GeneralRe: How to scan avalible wireless (802.11b) network in a MFC program? Pin
mango_lier25-Jun-03 4:06
mango_lier25-Jun-03 4:06 
GeneralRe: How to scan avalible wireless (802.11b) network in a MFC program? Pin
Robert Mao25-Jun-03 5:07
Robert Mao25-Jun-03 5:07 
GeneralUse WZC on XP? Pin
Robert Mao25-Jun-03 6:18
Robert Mao25-Jun-03 6:18 
Questionhow to change network and adapter setting in a MFC program? Pin
Robert Mao25-Jun-03 3:26
Robert Mao25-Jun-03 3:26 
AnswerRe: how to change network and adapter setting in a MFC program? Pin
Boris Schuetz25-Jun-03 4:42
Boris Schuetz25-Jun-03 4:42 
GeneralThanks, but... Pin
Robert Mao25-Jun-03 5:05
Robert Mao25-Jun-03 5:05 
GeneralRe: Thanks, but... Pin
Boris Schuetz25-Jun-03 5:37
Boris Schuetz25-Jun-03 5:37 
Generalany alternate way Pin
Halid Niyaz27-Aug-03 2:00
Halid Niyaz27-Aug-03 2:00 
Generaltricky thing with string Pin
Ilia Oussorov25-Jun-03 3:13
Ilia Oussorov25-Jun-03 3:13 
GeneralRe: tricky thing with string Pin
David Crow25-Jun-03 3:27
David Crow25-Jun-03 3:27 
GeneralRe: tricky thing with string Pin
Ilia Oussorov25-Jun-03 3:33
Ilia Oussorov25-Jun-03 3:33 
GeneralRe: tricky thing with string Pin
David Crow25-Jun-03 3:36
David Crow25-Jun-03 3:36 

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.