Reputation: 8505
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.
Upvotes: 13
Views: 44211
Reputation: 11
If you are using C++ standard I/O functions you can use these two useful MACROs:
_RPT1(0, "%f\n", sum);
TRACE("The value of x is %f\n", sum);
Here f
is double and the result can be viewed in DebugView.
P.S.: I'm using this code in MS Visual Studio 2019 C++;
Upvotes: 0
Reputation: 6947
If dealing with DLLs and Service EXEs like COM/DCOM or any other ATL project, you can also use this line of code to print out diagnostic messages in the form of MessageBox
windows as an alternative to printing messages to the console:
MessageBox(NULL, L"Com Object Function Called", L"COMServer", MB_OK | MB_SETFOREGROUND);
Example cases where I have used this include the _tWinmain
function, as well as constructors and destructors to keep track of instances.
Upvotes: 0
Reputation: 1035
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.
Upvotes: 11
Reputation: 798626
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.
Upvotes: 5