RE: DLL initialization (was: Loading new DLLs on old Windows)

"Simon O'Connor" <[email protected]>
Newsgroups gmane.games.devel.windows
Organization SC3D
Message-ID <[email protected]>
Hi Andras,


If the entry point (_DllMainCRTStartup, DllMain or a custom entry point)
returns FALSE, LoadLibrary() will return the error you're getting
(ERROR_DLL_INIT_FAILED).


There aren't many reasons why _DllMainCRTStartup (the function called before
DllMain) would fail, but a few examples would be: 

- memory (HeapAlloc() inside the CRT stuff failing).

- static/global object creation failing (e.g. out of stack, exceptions from
constructors etc).

- clashes between the version of the C runtime library used by the DLL and
the client app (pretty rare unless the DLL and client pass CRT objects
between each other).

- CRT file handle problems (e.g. if your client app redirected the standard
CRT handles in a bad way).

- [extremely unlikely, but...] MFC DLLs built with MSVC++ version 4 - there
were two versions of the 4.2 MFC DLLs that had identical names but were
slightly different - some apps (mostly OLE heavy ones) where the DLL used
one version and the client used another would have a few problems.


Have you done anything at all special with your DLLs? (re-basing, function
forwarding, delay loading etc)


I'd still have a DllMain with just a simple "return TRUE;" (and maybe a
DisableThreadLibraryCalls() for DLL_PROCESS_ATTACH notifications for
performance reasons where relevant) just to be certain I knew what was being
returned for entry.


Do all the plugin DLLs you load suffer from the same issue or is it just
one? -  try statically linking the offending DLL and see if the tester gets
any more specific error message (such as the missing export message box
you'll get if your DLL requires an OS function only present in a newer
version of Windows).


Cheers,

Simon O'Connor
Programmer @ Acclaim
& Microsoft DirectX MVP  

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On 
> Behalf Of Andras Balogh
> Sent: 12 February 2004 12:21
> To: [email protected]
> Subject: [GD-Windows] DLL initialization (was: Loading new 
> DLLs on old Windows)
> 
> My program supports dynamic loading of plugins. Every plugin 
> represents a class, and resides in a separate DLL. Instead of 
> exporting the class itself, I only export a factory function 
> and provide a header file with the declaration of the pure 
> virtual base class (ie. the interface). At runtime, I load 
> the DLL and call the exported factory function, which 
> instances an object and returns a pointer to the base class.
> 
> This architecture works like a charm on most machines. 
> However, on some configurations, my program reports the 
> following: "Error Code
> 1114: A dynamic link library (DLL) initialization routine failed."
> 
> But I have no clue why. Do I have to use DllMain? MSDN says 
> it's only an optional entrypoint.. My DLLs are dynamically 
> linked to the C/CPP run-time libraries.
> 
> 
> Thanks,
> 
> Andras
> 
> 
> 
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with a free 
> DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Gamedevlists-windows mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_id=555
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.572 / Virus Database: 362 - Release Date: 27/01/2004
>  
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 13/02/2004
 



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.