0
votes

I have a Win32 program that's built with VS2008, so my code is linked with MSVCR90.DLL and MSVCP90.DLL. However, it's also running code in a DLL (which I can't modify) that's been built with VS2005 and when code in that DLL prints to the clog stream it does it via MSVCR80.DLL and MSVCP80.DLL. Here's the problem: if I re-route std::clog in my code, I only affect code built against crt 9.0 libs, code using the older crt 8.0 wont have its output re-routed. So is there a way to re-route the clog stream in a DLL built against an older CRT?

I've investigated calling GetModuleHandle() and GetProcAddress() on the older CRT DLLs and have managed to re-route the C stderr stream (via _open_osfhandle and _dup2), however the C++ clog stream still seems to be unaffected. I think I also need to call ios_base::sync_with_stdio() in the older CRT lib but I couldn't get a valid address to that function. Any help would be greatly appreciated.

Thanks.

2

2 Answers

0
votes

Build a helper DLL using VS2005 - This DLL should simply export some functions to do the setup you need for VS8 runtime.

0
votes

Try also freopen... but this too might need to be called in the older CRT. Eric's suggestion of a helper DLL is massive overkill though, just use GetProcAddress to get a pointer to the VC8 version.

The most effective option is to redirect the standard streams when launching the process in the first place.

Another possibility is to delay-load the helper DLL, and perform the stream redirection before loading it. That way when MSVCRT80 loads, it will attach to the redirected stream.