I am new to C development on the PC but have been programming for 20+ years, at least 10 of that in C on Sun/Solaris. I am working in Visual Studio 2005 under WinXP. I have created a solution with 2 projects: the first is a library built from established open source code as a DLL. The second is a test program calling library functions built as a Win32 console app. All compiles and links succussfully (minor warnings about possible data loss because of type mismatches in the library code).
When I run, the program dies with an attempt to write to an invalid address. In the debugger, I found that the _iob array defined globally in the C library _file.c and which is used to hold the FILE * info for stdin, stdout, stderr, is resolved differently (placed at a different memory address) in the main than in the DLL.
The main passes stdout to an error output function in the DLL. The Standard C Library processing fails internally because it does a check of the FILE * pointer to see if it is in the _iob array. Because of the mismatch, it takes a path not intended for predefined file pointers and dies.
How does one get stdout to be shared between a main and a DLL?
I know that there are other problems with the configuration (like the reason for calling the error output routine in the first place) but I do not have conclusive information on those yet. I will be glad to answer any clarifying questions or comments.
I have built both the library and the main with the /MTd compiler switch.
Thanks,
LC
Start Free Trial