Advertisement

07.02.2008 at 01:51PM PDT, ID: 23535090
[x]
Attachment Details

Problem passing stdout from main to DLL function which calls fprintf

Asked by lcatnrl in C Programming Language

Tags: Microsoft, Visual Studio, VC/C++, 2005, Windows XP, not connected to Internet, C, memory issue between main and DLL

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,
LCStart Free Trial
 
Loading Advertisement...
 
[+][-]07.02.2008 at 02:26PM PDT, ID: 21920885

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 02:30PM PDT, ID: 21920905

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 02:39PM PDT, ID: 21920959

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 02:44PM PDT, ID: 21920996

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 02:49PM PDT, ID: 21921035

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2008 at 07:31PM PDT, ID: 21922271

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: Microsoft, Visual Studio, VC/C++, 2005, Windows XP, not connected to Internet, C, memory issue between main and DLL
Sign Up Now!
Solution Provided By: JohnGaby
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.03.2008 at 08:23AM PDT, ID: 21926364

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 08:32AM PDT, ID: 21926460

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628