LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What type is CAObjHandle?

Solved!
Go to solution

Hello,

 

I have a function that is exported in a DLL and called by TestStand. One of the parameters to the function is CAObjHandle seqContextCVI, which allows TestStand to pass in the sequence context. Inside my DLL function, I pass this sequence context to one of the callback functions. 

 

The callback functions, by definition, receive data in the form of a void pointer (*callbackData). I am sending the sequence context to the callback function in the form of this void pointer.

 

In the main function, I do the below code in order to turn SeqContextCVI into a void pointer:

 

void *callbackData = NULL;
callbackData = &seqContextCVI;

 

Once inside the callback function, I dereference this void pointer (after casting) to obtain the SeqContextCVI value. Below is that line of code:

 

CAObjHandle seqContextCVI = *((CAObjHandle*)callbackData);

 

It gives me a runtime error of "dereference of null pointer"

 

What am I doing wrong here? I believe that CAObjHandle is just an int type. Is it a pointer? If so, I could understand why the above operation does not work. 

 

0 Kudos
Message 1 of 4
(1,521 Views)

Hi,

 

I think that you are not doing any mistake, but are you sure that the address is valid when used .

 

Test code:

 

#include <cviauto.h>
#include <utility.h>

void CB(void* callbackData)
{
CAObjHandle seqContextCVI = *((CAObjHandle*)callbackData);
DebugPrintf("%d\n", seqContextCVI);
}

void main(void)
{
CAObjHandle seqContextCVI = 2;
void *callbackData = NULL;
callbackData = &seqContextCVI;
CB(callbackData);
}

 

 

0 Kudos
Message 2 of 4
(1,479 Views)

Is the handle even valid when your receive it from TestStand in your function? You need to systematically debug that and go back from where you see the error to see where that problem occurs. How could you test that?

 

Simple, try to insert a function (to read some valid attribute of the context for instance) in your function from which you initialize the callback. Does it return an error?

 

If that shows no problem you need to show us more about how you prepare the callback pointer. The code as you show it seems to look harmless but if you do some more pointer arithmetic there that somehow involves stack variables the stack of your function will potentially be gone at the time the callback function gets fired. Does that callback get fired after your function has returned to the TestStand executor? TestStand my already have re/deallocated that context somehow.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 4
(1,462 Views)
Solution
Accepted by topic author TestEngineer11

I am not seeing the problem anymore. I think it was being caused by another issue. 

0 Kudos
Message 4 of 4
(1,452 Views)