Dynamically loaded extension DLL's
Kevin Gainey -- kevin_g@idesign.com
Thursday, March 28, 1996
Environment: VC 4.1, Win95/WinNT
I have a need to implement dynamically loaded extension DLL's, and I'm
looking for information on how to do so.
I have searched in the help on-line, looked at the DLLHUSK sample, as
well as looking in the MFC FAQ. The best I've found is TN033, which
mentions using dynamically loaded extension DLL's.
But TN033 doesn't indicate what is different between the implementation
of a standard extension DLL use, and one that is dynamically loaded.
Specifically, I wonder how to prevent extension DLL's from being
automatically loaded.
If anyone could point me to some information where I could learn how to
implement dynamically loaded extension DLL's, I would appreciate it.
Kevin Gainey
KGAINEY@IDESIGN.COM
Mike Blaszczak -- mikeblas@msn.com
Sunday, March 31, 1996
[Mini-digest: 2 responses]
> Environment: VC 4.1, Win95/WinNT
Thanks.
> I have searched in the help on-line, looked at the DLLHUSK sample, as
> well as looking in the MFC FAQ. The best I've found is TN033, which
> mentions using dynamically loaded extension DLL's.
TN033 contains everything you need. Updates of the MFC documentation in the
VC++ online references will actually document the AfxLoadLibrary(),
AfxFreeLibrary(), and related functions so that you can search on them.
> But TN033 doesn't indicate what is different between the implementation
> of a standard extension DLL use,
I'm not sure I understand this sentence. What do you mean by "the
implementation of [a DLL] use"?
> and one that is dynamically loaded.
> Specifically, I wonder how to prevent extension DLL's from being
> automatically loaded.
I'm not sure what you mean by "automatically loaded". Do you mean that you
don't want some of the DLLs your application uses to be loaded when your
application first starts? If that's the case, you shouldn't link to the
import library of that DLL. Instead, you should explicitly call
AfxLoadLibrary() to get the library into your process and AfxFreeLibrary()
when you're done with it. Inbetween, you'll need to call GetProcAddress() to
get a pointer to each function that you want to call.
.B ekiM
TCHAR szIggyPop[] = _T("There's something here they've got to face: it's the
same for everyone.");
-----From: Geoffrey Nicholls
>I have searched in the help on-line, looked at the DLLHUSK sample, as
>well as looking in the MFC FAQ. The best I've found is TN033, which
>mentions using dynamically loaded extension DLL's.
>
>But TN033 doesn't indicate what is different between the implementation
>of a standard extension DLL use, and one that is dynamically loaded.
>Specifically, I wonder how to prevent extension DLL's from being
>automatically loaded.
I have this working on WFW 3.11, and expect a little bit of work to get it
to 32 bit windows when the time comes. Still I think this will help. I use
TN033 for the settings to create an MFC extension DLL. Here's the basis of it:
///
// code in the DLL
///
storage AFX_EXTENSION_MODULE g_extensionDLL;
storage HINSTANCE g_hinstDll;
extern "C" int CALLBACK LibMain(
HINSTANCE hInstance,
WORD /* wDataSegment */,
WORD /* wHeapSize */,
LPSTR /* lpszCmdLine */)
{
// Extension DLL one-time initialization - do not allocate memory here,
// use the TRACE or ASSERT macros or call MessageBox
AfxInitExtensionModule(g_extensionDLL, hInstance);
// remember our instance
g_hinstDll = hInstance;
// done
return(1);
}
void WINAPI _export InitInstance(
CMultiDocTemplate * & tplAdd )
{
static BOOL fLinkLib = FALSE;
// create a new CDynLinkLibrary for this app
if (!fLinkLib)
{
new CDynLinkLibrary(g_extensionDLL);
fLinkLib = TRUE;
}
tplAdd = new CMultiDocTemplate(
IDR_TEXTTYPE,
RUNTIME_CLASS(DMyDocument),
RUNTIME_CLASS(DMyMDIChild),
RUNTIME_CLASS(DMyView));
}
///
// code in the EXE
///
BOOL CWinApp::InitInstance()
{
...
hinstLibrary = LoadLibrary("DYNAMIC.DLL");
lpfnInit = GetProcAddress(hinstLibrary, "InitInstance");
(*lpfnInit)(tplDynamic);
AddDocTemplate(tplDynamic);
...
}
Please let me know how this code ports to 32 bit windows.
Good luck,
Geoff Nicholls
| Вернуться в корень Архива
|