15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Unable to deserialize classes from dll (Extension Dll)

Sathiyamurthy Thiruvengadathan -- sathiya@colmds2.com
Tuesday, March 18, 1997

Environment: MSVC 4.2b Windows NT 4.0

Hi,

I had a bunch of CObject derived classes exported from a DLL. This DLL
was built with "Use MFC in a Static Library" option. Some of these
classes had serialisation/deserialisation functioniality and they were
working fine. For certain reasons I had to change the build settings to
"use MFC in a shared DLL" option. After this change everything else
works fine, but the deserialisation doesn't work. Debugging thru the MFC
source I figured out that I'm not getting the CRuntimeClasses for the
classes defined in the DLL. The CRuntimeClass::Load() function fails and
returns NULL.
	After reading MFC Tech Notes - TN033 - I realised what the problem is
and I added the following DllMain function (till then the DLL did not
have one) as suggested.


static AFX_EXTENSION_MODULE NEAR extensionDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		if (!AfxInitExtensionModule(extensionDLL, hInstance))
			return 0;
		new CDynLinkLibrary(extensionDLL);
	}
	return 1;  
}

Even after adding this function, though the function gets executed and
AfxInitExtensionModule returns TRUE, CRuntimeClass::Load() cannot find
the CRuntimeClasses of the classes defined in the DLL. I checked up the
DLLHUSK sample to see if I need to do anything more. But I couldn't
figure out. Can somebody tell me what is that I am doing wrong? I would
appreciate any help in this regard. I have a deadline staring at me.
Thanks in advance.

Sathya
sathiya@colmds2.com



Doug Brubacher -- Doug_Brubacher@compuware.com
Saturday, March 22, 1997

     Give 
         AFX_MANAGE_STATE( AfxGetStaticModuleState() );
     a try.  It should be the first line in any entry point into your DLL.  
     This is definitely a necessity when accessing resources, and may 
     resolve the problem you are reporting as well.
     
     See the documentation:
     Regular DLLs Dynamically Linked to MFC
     
     
     Because this kind of DLL uses the dynamic link library version of MFC, 
     you must explicitly set the current module state to the one for the 
     DLL. To do this, use the AFX_MANAGE_STATE macro at the beginning of 
     every function exported from the DLL. 
     
     Regards,
     
     Doug Brubacher
     Doug_Brubacher@compuware.com




Sathiyamurthy Thiruvengadathan -- sathiya@colmds2.com
Tuesday, March 25, 1997

Doug Brubacher wrote:
> 
>      Give
>          AFX_MANAGE_STATE( AfxGetStaticModuleState() );
>      a try.  It should be the first line in any entry point into your DLL.
>      This is definitely a necessity when accessing resources, and may
>      resolve the problem you are reporting as well.
> 
>      See the documentation:
>      Regular DLLs Dynamically Linked to MFC
> 
>      
>      Because this kind of DLL uses the dynamic link library version of MFC,
>      you must explicitly set the current module state to the one for the
>      DLL. To do this, use the AFX_MANAGE_STATE macro at the beginning of
>      every function exported from the DLL.
> 
>      Regards,
> 
>      Doug Brubacher
>      Doug_Brubacher@compuware.com

Thanks Doug, it did work. I just added AFX_MANAGE_STATE macro at the
beginning of my Serialize function and everything works fine. Tho' the
documentation says that I need to instantiate a CDynLinkLibrary object
in my DLL initialisation function, I didn't do that (b'cos I was
getting  linker errors if I use CDynLinkLibrary and AFX_MANAGE_STATE in
the same DLL) and everything works fine.

Thanks once again Doug,
Sathya




Become an MFC-L member | Вернуться в корень Архива |