tags:

views:

195

answers:

3

Hi,

I have an application which uses C# for front end and C++ DLL for the logic part. I would want to print error messages on console screen from my C++ DLL even when the C# GUI is present. Please let me know how to do this.

Thanks, Rakesh.

+2  A: 

You can use OutputDebugString in C++ DLL, and then execute DebugView to get the messages

Francis
+2  A: 

Unless the application is started from a console, stdin, stdout, and stderr won't even exist and any attempt to use e.g. printf() will fail. Either open your own console or use a debugging mechanism such as OutputDebugString() suggested earlier.

Ignacio Vazquez-Abrams
A: 

You can use AllocConsole() to create a console window and then write to standard output.

If you are using C or C++ standard I/O functions (as opposed to direct win32 calls), there are some extra steps you need to take to associate the new console with the C/C++ standard library's idea of standard output. http://www.halcyon.com/~ast/dload/guicon.htm explains what you have to do and why, with complete code.

Greg Najda
hey Greg, could you please expand on using AllocConsole(). Any links for reference?
Rakesh K
I added a link to the MSDN documentation for AllocConsole(). It's very simple. Just call AllocConsole() to create a console window for your application and check the return value to make sure it didn't fail for some reason.
Greg Najda
I used AllocConsole to create a console window but nothing was being printed on the screen. Any idea why this is happening?
Rakesh K
I apologize, I've only used AllocConsole() from C#. It appears that there are some extra hoops you have to jump through when using C or C++ standard library I/O functions because of the abstraction layers between the functions and the win32 stdout/stdin/stderr handles. I've added a link to the answer that explains the extra steps you need to do.
Greg Najda