LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I access data attached to an event within the event handler function?

Solved!
Go to solution

Hello,

 

 

 

In my LabWindows code I'm trying to use a DLL that was developed in .NET (C#).  I used the wizard built in to labwindows which converts the DLL to a usable "instrument".  Nearly everything seems to be working, except I'm having 1 problem.

 

There is an event (defined in the DLL) that I am able to detect.  I know that the event callback is being called at the appropriate time.  But the problem is that within that function, I cannot access the data that is supposed to be attached to the event.  It worked fine in C#, but I don't know how to do it in LabWindows.  Here is what the event handler function looked like in C# :

 

void AppLoaderEventCallback (CommonLib.CommandResult MyResults)

{

MyResults is used in the body of this function

}

 

But in LabWindows I can't seem to access the MyResults data structure.  Here is what I'm doing:

 

static int CVICALLBACK AppLoaderEventCallback (CommonLib_CommandResult MyResults)

{

I can't access MyResults in here

}

 

 

Can you help me with this?  Am I doing something wrong?

 

Thank you very much for your help.

 

 

-Mike 

0 Kudos
Message 1 of 5
(3,624 Views)

Hello Mike,

 

I have a few additional questions for you:

 

  1. What is the nature of the MyResults data that you are expecting (i.e. is it a primitive data type, an array, a structure of some sort, etc.)?
  2. When you indicate that "the event callback is being called at the appropriate time", do you mean that the event is only being fired or that the event is firing and the callback is indeed executing too as we would hope?
  3. Can you describe more about what you mean by being "unable to access the data"?  Is MyResults empty?  Are its contents "nonsense"?  Do privileges prevent you from accessing the data?

Thanks in advance for these answers!

0 Kudos
Message 2 of 5
(3,590 Views)

Hi Matt

 

In response to your followup questions:

 

1.  MyResults is a data structure of type CommonLib.CommandResult.  I want to access some of its properties. 

 

2.  The callback is executing when the event fires, as desired.

 

3.  When I say I'm unable to access the data, I mean an error occurs when I try to get a property of MyResults.  In C# I would just say "MyResults.CR", but in Labwindows I have to do "CommonLib_CommandResult_Get_CR (MyResults, &CR, ....);".

When I attempt to do that, I get a run-time error.  The error message seems to be telling me that MyResults isn't a valid instance of a CommonLib_CommandResult object.  "An invalid object handle was passed to the LabWindows/CVI .NET Library"

 

My guess is that I'm doing something wrong in the sequence of parameters for my callback function.  Right now I'm just trying to copy what worked for me in C# :

int CVICALLBACK AppLoaderEventCallback (CommonLib_CommandResult MyResults) 

 

 

Thanks for your help, I really appreciate it.

 

-Mike 

0 Kudos
Message 3 of 5
(3,581 Views)
Solution
Accepted by topic author chum80

I think your callback function declaration may not be quite correct. Look at the function panel help of the 'callback function' parameter of the generated __Create function associated with this event. This shows the expected declaration of the callback function - make sure your callback function is declared the same way.

0 Kudos
Message 4 of 5
(3,568 Views)

Thanks!!!!  That's what I needed.  I just didn't know where to find the correct format for the callback declaration.

0 Kudos
Message 5 of 5
(3,553 Views)