Visual Studio C++ - using the logger callback

20 views
Skip to first unread message

Pete Huish

unread,
Mar 10, 2025, 8:44:32 PMMar 10
to libplctag
I am trying to set up a logger callback in a VS C++ application and I am having an issue compiling it.

The callback function is defined as below:

void CSRMIntView::LogCallback(int32_t tag_id, int debug_level, const char* message)
{
CString strMsg;

if (!m_bCallLogging)
return;

strMsg.Format("libplctag %s", message);
LOGSTRING(strMsg);

return;
}

The function setting the callback is as follows:

int CSRMIntView::SetLogCallback()
{
CString strData;
int rc;

rc = plc_tag_register_logger(&LogCallback);
if (rc != PLCTAG_STATUS_OK)
{
strData.Format("ERROR: %s: Could not register log callback",                           plc_tag_decode_error(rc));
LOGSTRING(strData);
return 1;
}

return(1);
}

The compiler generates an error on the plc_tag_register_logger function:
argument of type "void (CSRMIntView::*)(int32_t tag_id, int debug_level, const char *message)" is incompatible with
parameter of type "void (*)(int32_t tag_id, int debug_level, const char *message)"

I am not sure how to resolve this.

thanks,

pete

Kyle

unread,
Mar 11, 2025, 3:48:30 PMMar 11
to libplctag
You cannot pass a method pointer as an argument to a function that expects a function pointer.  They are not the same.

There is a discussion of this here that might be useful.  I would suggest either writing a stand-alone function or using a static method.

Best,
Kyle
Reply all
Reply to author
Forward
0 new messages