473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

API call back error from deferent Thread

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);

}
Nov 17 '05 #1
1 1486

I can't say for sure what's causing the exception. I twould be useful
to see the native and managed declaration of LOGCALLBACKINFO too.

SetLogCallBack(new DelegateLogOutputCallBack(internalSetLogCallBackHa ndler));


Here you should keep a reference to the callback delegate to make sure
it's valid as long as the callback is needed. Otherwise the delegate
may get garbage collected.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sergey Romanov | last post by:
I have app like Computer Managment app. on windows. I have everithing in tree. I whant deferent context menu appear on deferent treenode items. How can I do this?
0
by: JDK | last post by:
This may be entirely the wrong forum for this message, but I wanted to give it a try. I am creating an ASPX page, with C# code behind, and am calling on a C# helper class, which in turn is...
0
by: [Yosi] | last post by:
I search solution for a little bit strange problem , I working on an application which includes a button. Click on this button will create number of threads each one execute deferent executable...
4
by: Tim Gallivan | last post by:
Hello group, I'm trying to develop a proof of concept webservice which asynchronously calls a function in a DLL. The function raises an event when it is finished, and works when used as part of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.