fputs to stderr causes exception when called from managed/unmanaged mixed mode DLL

  • Thread starter Yoni Rabinovitch
  • Start date
Y

Yoni Rabinovitch

Hi,

We have a large code base of "regular" C++ code (not MFC, COM or ATL).

With VC6.0, we used to compile the "regular" C++ code as static
libraries (.lib files), and then we would link the .lib files with an
MFC GUI "front end".

The "regular" C++ can also run as a standalone .EXE (with no GUI).

The "regular" C++ can be built and runs correctly as a standalone .EXE
with VC7.1 too.

We are now contemplating upgrading the GUI "front end" to C#. This
entails adding a Managed C++ "wrapper" DLL, which gets called frmo C#,
and in turn calls the Unmanaged C++.

The unmanaged C++ uses static variables, and so we have followed the
instructions in the MSDN article on "Converting Managed Extensions for
C++ Projects from Pure Intermediate Language to Mixed Mode". The
initialisation of static variables seems to be working correctly
(verified with breakpoints).

We have got to the point where the C# calls the Managed C++ Wrapper,
which calls Unmanaged C++, but we are getting a
System.NullReferenceException.

The exception is happening when a call is made to fputs, to output a
string to the sdterr, when function _lock_file calls
EnterCriticalSection.

Here is the stack trace:


NTDLL.DLL!_RtlEnterCriticalSection@4() + 0x11e87
msvcr71.dll!_lock_file(void * pf=0x1009d0d4) Line 236 C
msvcr71.dll!fputs(const char * string=0x1009df74, _iobuf *
stream=0x1009d0d4) Line 53 + 0x9 C
AppsEMSWrapper_Take1.dll!RTDiagStream::write(const char *
string=0x1009df74) Line 120 + 0x12 C++
AppsEMSWrapper_Take1.dll!showBanner() Line 189 + 0x13 C++
AppsEMSWrapper_Take1.dll!RTMain::mainLine() Line 221 C++
AppsEMSWrapper_Take1.dll!RTMain::entryPoint(int argc=0x00000006, const
char * const * argv=0x0012f624) Line 67 C++
AppsEMSWrapper_Take1.dll!ModelInterface::modelMainEntryPoint(int
RunAsLCT=0x00000001) Line 130 + 0xb C++
appsemswrapper_take1.dll!AppsEMSWrapper_Take1.ModelInterfaceWrapper.modelMainEntryPointWrapper(__int32
RunAsLCT = 0x1) Line 17 C++
ConsoleApplication1.exe!ConsoleApplication1.Class1.Main(string[] args
= {Length=0x0}) Line 33 C#


Any ideas, anyone ?????

Thanks !!!
 
G

George Ter-Saakov

Probably you did not initialized C runtime
Did you call
__crt_dll_initialize()

George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top