Explicitly Linking to Classes in DLL's
Explicitly Linking to Classes in DLL'sSometimes Explicit Linking to DLL's is advantageous over implicit linking. For example, if at runtime the DLL is not found the application can display an error message and still continue. Explicit linking is also useful if you want users to provide a plugin for your application, in which case you could explicitly load the dll and call some predefined set of functions in it.
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">Explicit linking to global(non-member) C/C++ is quite easy. For example, suppose you wan't to call to a function ExportedFn in a dll. You can simply export the function like this (or through the def file):-
extern "C" _declspec(dllexport)void ExportedFn(int Param1, char* param2);The extern "C" linkage specification is required because otherwise C++ compiler generates a decorated name for the function and the function would not be exported with the name "ExportedFn" instead it would be exported something like "??ExportedFn@QAEX" . If this function resides in a DLL called DLL1.dll a client exe can call this function simply like this :-
HMODULE hMod = LoadLibrary("Dll1.dll");typedef void (*PExportedFn)(int, char*);PExportedFn pfnEF = (PExportedFn)GetProcAdress("ExportedFn");pfnEF(1, "SomeString");
<div class="toolbox noBullets colRight" style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 10px; float: right; width: 160px; font-size: 11px; clear: both; padding: 10px; border: 1px solid #cccccc;">
[*]Post a comment
[*]Email Article
[*]Print Article
[*]http://www.codeguru.com/newimg/images/icon_share.gif Share Articleshttp://www.codeguru.com/newimg/images/arrow_down_spblue.gif
页:
[1]