Problems passing iostreams to DLL's 
Author Message
 Problems passing iostreams to DLL's

I'm having a problem using the Standard C++ iostreams between a console
application and a DLL

when staticaly linking the C runtime library (Visual C++ 6.0 Enterprise).
The following is a simple test case:

File Console.cpp: (creates Console.exe based on simple console app wizard)

#include <iostream>
void DllFunction(std::ostream&);   // Prototype for Dll function
void main (void)
{
   DllFunction(std::cout);  // Call a function in the DLL passing cout

Quote:
}

File Dll.cpp: (Created DLL based on simple DLL wizard)

#include <iostream>
__declspec(dllexport) void DllFunction(std::ostream& str)
{
   str << "Characters: " << (int) 6 << std::endl;

Quote:
}

The attempt to stream out the integer (6) throws a bad_cast exception within

locale::use_facet (due to _L._Iscloc() returning 0).

If I move this code into the console app or link dynamically to the runtime,
things are fine.

Does anyone know if this is a compiler/CRT library problem and if so, is
there a workaround

while still statically linking the CRT and using DLL's?

Thanks!

Mike



Mon, 30 Apr 2001 03:00:00 GMT  
 Problems passing iostreams to DLL's
Both dll and .exe should be linked to dll version of the c-runtime.
Otherwise each module gets its own heap and passing objects that may
allocate/delete memory internally will not work


Quote:
>I'm having a problem using the Standard C++ iostreams between a console
>application and a DLL

>when staticaly linking the C runtime library (Visual C++ 6.0 Enterprise).
>The following is a simple test case:

>File Console.cpp: (creates Console.exe based on simple console app wizard)

>#include <iostream>
>void DllFunction(std::ostream&);   // Prototype for Dll function
>void main (void)
>{
>   DllFunction(std::cout);  // Call a function in the DLL passing cout
>}

>File Dll.cpp: (Created DLL based on simple DLL wizard)

>#include <iostream>
>__declspec(dllexport) void DllFunction(std::ostream& str)
>{
>   str << "Characters: " << (int) 6 << std::endl;
>}

>The attempt to stream out the integer (6) throws a bad_cast exception
within

>locale::use_facet (due to _L._Iscloc() returning 0).

>If I move this code into the console app or link dynamically to the
runtime,
>things are fine.

>Does anyone know if this is a compiler/CRT library problem and if so, is
>there a workaround

>while still statically linking the CRT and using DLL's?

>Thanks!

>Mike



Thu, 03 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. iostream vs iostream.h -- VC++5 vs VC++6 problem

2. Problem with 'struct' passing

3. Passing arrays to dll's

4. Passing Data Between Exe's using Dll

5. Passing Recordsets to .dll's

6. Passing Strings via C DLL's and Visual Basic

7. Passing Object Pointers to/from DLL's

8. Writing dll's to be called from visual basic, and passing arrays

9. Passing CStringArray objects between functions in separate DLL's

10. Question about 16 bit DLL's and passing parameters

11. Passing Object Pointers to/from DLL's

12. Passing map's across dlls

 

 
Powered by phpBB® Forum Software