www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Call to FreeLibrary sets stdout to invalid state.

Using DMD 0.99 and DMC 8.38n
Using default line-command arguments on all utils
Using mydll.dll provided in the dmd/samples/d/mydll directory

Calling FreeLibrary against a dll built using DMD/DMC sets stdout and stdin to
an invalid state.

// the last printf never displays
import std.c.windows.windows;
void main(){
HMODULE mod = LoadLibrary("mydll.dll"); // from DMD/samples/d/mydll
printf("You will never see this print.\n");

The equivalent code in C also yeilds the same result.  Likewise, a dll built
using DMC using a non-trival DllMain function causes the same behavior.


Basically, stdout and stdin are "automagically" set to an EOF-like state (in C
"feof(stdin)" return false) after the call to FreeLibrary(): nothing goes in and
nothing comes out.  Everything else runs fine after FreeLibrary: file io still
works, socket io still works, no exceptions are thrown, and GetLastError()
faithfully returns 0.

I've been able to recreate the above in DMC, with a 100% C-built Dll using the
same .def file as the mydll sample.  The results are also the same when calling
that dll from a host program written in MSVC6, DMD and DMC.  Unless I'm horribly
mistaken on how to do compose dll's using Digitalmars' technology, this is what
you get the instant you unload any DMC/DMD built dll.  

The problem seems to only manifest when a proper DllMain() method is exported
from the library.  If none is provided, or if the given implementation can be
optimized away, the error does not ocurr.

- Pragma
Aug 20 2004