I have an API, with a call back error definition. API receive reference to C#
output message function (write to text box using Invoke since I use thread).
Every thing is working fine API can write a message to my GUI textbox, but
when I access the API from another THREAD , API try to call this function
(reference to output message function), I get an exception. I understand that
this exception somehow because invoke issue, but how can I solve this
problem. In my GUI C# code I use the Invoke but I not reach the C# since the
exception in my API.
******
API definition:
******
typedef void (__stdcall * LOG_CALLBACK)(LOGCALLBACKINFO *);
LOG_CALLBACK ptrLogCallBackFunction = NULL;
******
API set function:
******
DLL_API void CALL_SetCallbackGUI (LOG_CALLBACK ptrLOG_CALLBACK);
******
C#:
******
[DllImport("CALL_DLL.dll", EntryPoint="CALL_SetCallbackGUI_NoStyleLog",
CallingConvention=CallingConvention.StdCall)]
public static extern int SetLogCallBack(DelegateLogCallBack
delegate_callback);
Set API reference to my internal C# function by:
SetLogCallBack(new DelegateLogOutputCallBack(internalSetLogCallBackHa ndler));
public void internalSetLogCallBackHandler(ref LOGCALLBACKINFO cInfo)
{
this.mForm.invoke_outPut(cInfo.log_text);
}
public void invoke_outPut(string outStr)
{
object [] args = new object[1];
args[0] = outStr;
InvokerFunctionString funcP = new
InvokerFunctionString(this.mForm.outPut);
this.mForm.Invoke(funcP,args);
}