I have a wrapper around a call to gSite.CallFunction() for the _Trace command in AmiBroker. When I pass it a static string like so,
ab_Trace("This is a static string");
Everything goes fine. DebugView picks it up just like when _Trace is called from AmiBroker. However, when I call it with a string created using run-time values, as below,
float NumericValue = 15;
ab_Trace("This string is created at runTime: " + to_string(NumericValue));
everything seems to work but DebugView does not pick up the message. When I say "everything seems to work", what I mean is that it throws no errors, and when I do a VS debug session, the string shows up in the VS output window, and nothing seems amiss when I set a breakpoint and walk through the function looking at the variable values. The same behavior/problem occurs if I instead pipe to clog or send the string directly through OutputDebugString() instead of Amibroker.
I am running DebugView as administrator and it is monitoring all streams, as you can see from this screenshot:
I have also tried sending the string using .data() and .c_string() with no luck. I have tried concatenating "\n\0" to the end of the string, and no luck. I've been googling this for a few days and have found nothing that helps/explains this behavior.
What is the difference between static and run-time created strings which keeps DebugView from receiving the latter? Can I do anything about it?
Code for the wrappers is below,
void ab_Trace(const char *message) {
AmiVar _args[1];
string msg(message);
size_t msgSize = msg.length();
_args[0].type = VAR_STRING;
_args[0].string = (char*)gSite.Alloc(static_cast<unsigned int>(sizeof(char) * (msgSize + static_cast<size_t>(1))));
strcpy_s(_args[0].string, msgSize + static_cast<size_t>(1), message);
gSite.CallFunction("_TRACE", 1, _args);
} // End ab_Trace
void ab_Trace(string & message) {
AmiVar _args[1];
size_t msgSize = message.length();
_args[0].type = VAR_STRING;
_args[0].string = (char*)gSite.Alloc(static_cast<unsigned int>(sizeof(char) * (msgSize + static_cast<size_t>(1))));
strcpy_s(_args[0].string, msgSize + static_cast<size_t>(1), message.data());
gSite.CallFunction("_TRACE", 1, _args);
} // End ab_Trace