Re: DLL spitting out false mem leaks
MiG wrote:
Hi there,
I'm manually loading and unloading a MFC-based DLL from within a non MFC
application multiple times and whenever it is instructed to unload it
spits out a memory leaks debug report.
Now, these memory leaks aren't leaks at all and are the result of the
mem allocs in the main program (the non-MFC one) responsible for calling
the DLL.
How can I get rid of these annoying false positives mem leaks?
Many thanks,
Miguel
BTW, here is a few code snippets to illustrate how I'm loading/unloading
the DLL.
bool C3dSim::RunLauncher() const
{
HMODULE hLauncher;
int (PASCAL* pfRunLauncher)(bool);
int nRetCode;
// load library, retrieve pointer to proc and execute it.
hLauncher = ::LoadLibrary(_T("launch.dll"));
if(hLauncher == NULL) return(false);
pfRunLauncher = (int (PASCAL *)(bool))::GetProcAddress(hLauncher,
(LPCSTR)0x0001);
if(pfRunLauncher != NULL)
{
nRetCode = (*pfRunLauncher)(!m_bLauncherRan);
if(!m_bLauncherRan) m_bLauncherRan = true;
}
else
nRetCode = IDCANCEL;
::FreeLibrary(hLauncher); // at this point a few mem leaks
// are reported (false positives)
return(nRetCode != IDCANCEL);
}
pfRunLauncher points to the following function in launch.dll:
extern "C" int PASCAL EXPORT RunLauncher(bool bFirstRun)
{
// dynamically linking against MFC DLLs...
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CLaunchDlg oDlg(bFirstRun);
return(oDlg.DoModal());
}