473,387 Members | 1,606 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,387 software developers and data experts.

Threading - need help making callback function a thread

Jim
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or
freeze, or do strange stuff. When I remove this callback
function it works great. Problem is I need this callback
function to implement my state machine for the program so
I think I need to encapsulate this callback function into
its own process, but it takes 4 parameters. I have looked
all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?
Nov 15 '05 #1
3 2020
Jim,

What is the mechanism that you are passing? Are you passing a COM
interface pointer, or are you passing a function pointer (which is marshaled
from a delegate into unmanaged code)? Each way has its own considerations,
but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim" <je******@nationsfirstcorp.com> wrote in message
news:02****************************@phx.gbl...
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or
freeze, or do strange stuff. When I remove this callback
function it works great. Problem is I need this callback
function to implement my state machine for the program so
I think I need to encapsulate this callback function into
its own process, but it takes 4 parameters. I have looked
all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

Nov 15 '05 #2
Jim
I am sending a fucntion pointer. here is my Event Handler
Method. What is happening, is some how when my
eventhandler is fired it will lock up my program. I think
there is some memory issues here and I can't figure it
out.

unsafe public void EventHandler (void* vpUserData, uint
uiEvent, uint uiParam0, uint uiParam1)

{
EvQ[iQIn].uiUserData = (uint)vpUserData;

EvQ[iQIn].uiEvent = uiEvent;

EvQ[iQIn].uiParam0 = uiParam0;

EvQ[iQIn].uiParam1 = uiParam1;

richTextBox1.AppendText("\r\nEvent Handler " +
iQIn.ToString());

richTextBox1.AppendText("\r\nEvent : " + uiEvent.ToString
());

iQIn ++;

if(iQIn == 200) //Queue at max compacity

{

iQIn = 0; //Reset to 0

}

if(uiEvent == 215)

{

if(uiParam0== TONE_DIALTONE)

{

richTextBox1.AppendText("\r\n WE HAVE DIALTONE \r\n");

}

if(uiParam0 == TONE_RINGBACK)

{

richTextBox1.AppendText("\r\n WE HAVE RINGBACK \r\n");

}

if(uiParam0 == TONE_BUSY)

{

richTextBox1.AppendText("\r\n WE HAVE BUSY \r\n");

}

}
}
-----Original Message-----
Jim,

What is the mechanism that you are passing? Are you passing a COMinterface pointer, or are you passing a function pointer (which is marshaledfrom a delegate into unmanaged code)? Each way has its own considerations,but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim" <je******@nationsfirstcorp.com> wrote in message
news:02****************************@phx.gbl...
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or freeze, or do strange stuff. When I remove this callback function it works great. Problem is I need this callback function to implement my state machine for the program so I think I need to encapsulate this callback function into its own process, but it takes 4 parameters. I have looked all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

.

Nov 15 '05 #3
I'll bet that your callback is being called on a thread other then the UI
thread. I think you should be using this.Invoke on any calls to your UI
controls.

Jeffrey
"Jim" <je******@nationsfirstcorp.com> wrote in message
news:f5****************************@phx.gbl...
I am sending a fucntion pointer. here is my Event Handler
Method. What is happening, is some how when my
eventhandler is fired it will lock up my program. I think
there is some memory issues here and I can't figure it
out.

unsafe public void EventHandler (void* vpUserData, uint
uiEvent, uint uiParam0, uint uiParam1)

{
EvQ[iQIn].uiUserData = (uint)vpUserData;

EvQ[iQIn].uiEvent = uiEvent;

EvQ[iQIn].uiParam0 = uiParam0;

EvQ[iQIn].uiParam1 = uiParam1;

richTextBox1.AppendText("\r\nEvent Handler " +
iQIn.ToString());

richTextBox1.AppendText("\r\nEvent : " + uiEvent.ToString
());

iQIn ++;

if(iQIn == 200) //Queue at max compacity

{

iQIn = 0; //Reset to 0

}

if(uiEvent == 215)

{

if(uiParam0== TONE_DIALTONE)

{

richTextBox1.AppendText("\r\n WE HAVE DIALTONE \r\n");

}

if(uiParam0 == TONE_RINGBACK)

{

richTextBox1.AppendText("\r\n WE HAVE RINGBACK \r\n");

}

if(uiParam0 == TONE_BUSY)

{

richTextBox1.AppendText("\r\n WE HAVE BUSY \r\n");

}

}
}
-----Original Message-----
Jim,

What is the mechanism that you are passing? Are you

passing a COM
interface pointer, or are you passing a function pointer

(which is marshaled
from a delegate into unmanaged code)? Each way has its

own considerations,
but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim" <je******@nationsfirstcorp.com> wrote in message
news:02****************************@phx.gbl...
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or freeze, or do strange stuff. When I remove this callback function it works great. Problem is I need this callback function to implement my state machine for the program so I think I need to encapsulate this callback function into its own process, but it takes 4 parameters. I have looked all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

.

Nov 15 '05 #4

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

Similar topics

1
by: Jim West | last post by:
Good day all, Ok, I'm starting to get the hang of this Python thing...really pretty cool actually. Again, thanx to those that have helped me thus far. I now have another stumbling block to...
5
by: Francois De Serres | last post by:
Hiho, could somebody please enlighten me about the mechanics of C callbacks to Python? My domain is more specifically callbacks from the win32 API, but I'm not sure that's where the problem...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
3
by: Asad | last post by:
Hi, I am trying to write some threading code to my application. The reason I've been tempted to do this is because, I am doing some FTP uploads, and sometimes during the put method, the...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
5
by: greg.merideth | last post by:
I have a class that I've provided an event for to be called when the processing in the class is complete (a callback). The class spins up a series of threads for the background operation and I'm...
9
by: sreekant | last post by:
Hi folks What am I doing wrong in the following? I just want to run fluidsynth in the background. ######################################### class MyThread(threading.Thread): def __init__(self,...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.