LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CA_ServerGetObjData() returns invalid handle error

I have a custom top level object in an activex EXE server. This object has its own data.
I allocated memory for the data and stored
it in the object itself at the time of
object creation. (using CA_ServerSetObjData())

But when I tried to get the pointer to the
object data for cleanup (using CA_ServerGetObjData())
just before the object gets deleted,
CA_ServerGetObjData() returns invalid handle error.

I am able to use CA_ServerSetObjData(), CA_ServerReleaseObjData() calls in other places
for the same object with out any errors.

Thanks for your time.
Mano

Here is the code snippet where I am getting the error

// This code is a part of the object callback function
if (event == CA_SERVER_EVENT_OBJECT_DE
STROY) {
// Get the object data and dispose it
hrChk (CA_ServerGetObjData (objHandle, &pObjData));
if (pObjData) {
free (pObjData);
}
hrChk (CA_ServerReleaseObjData (objHandle));
}
0 Kudos
Message 1 of 3
(3,024 Views)
Hi,

This is a bug in the current version of CVI (version 7.0). We will fix this in the next version. Thanks for bringing this to our notice. The bug was occurring because we are accidentally marking the handle to be invalid before passing it to the object callback function during destruction.

For now, you can work-around this bug by keeping track of the memory yourself and not calling CA_ServerGetObjData/CA_ServerReleaseObjData in the object callback function. You can associate the object handle with the pointer in a struct during object creation, and store the structs in a list. During object destruction, you can look up the struct in the list and get the pointer and free it. This is similar to what we do internally to get the object data from the handle. The toolb
ox.fp instrument has a simple list that you can use for this purpose. You can also do this in other ways instead of using structs and lists.

If the memory involved is not too big, then you may also consider letting the memory leak, as Windows will reclaim the memory anyway when the server exits.

Best regards,
Mohan
CVI R&D
0 Kudos
Message 2 of 3
(3,024 Views)
Thanks for your input.

Mano
0 Kudos
Message 3 of 3
(3,024 Views)