LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX Server String Property

Solved!
Go to solution

Hi everybody,

I'm currently developing an application using LabWindows/CVI 8.1 on an WinXPSP3 machine. To allow easy automation of the functions in my application, I decided to add an ActiveX Server interface to my application and first tests look very promising. However, after I have introduced a string-type property to my ActiveX server I get a strange error when the get method is called by the client. The automatically generated code of the ActiveX server receives the string from the application and converts it into a BSTR that is returned to the client. The string pointer returned by the application function is converted into this BSTR and later on in the automatically genereated function the string pointer is freed with a call to CA_FreeMemory (). In general this should works fine but when I run my application in Debug mode the execution is halted at this point (even when there is no break point) and the debug window shows the following message:

 

HEAP[application_debug.exe]: Invalid Address specified to RtlFreeHeap( 00140000, 027995E0 )

 

Actually the allocated memory is not freed.

I have generated a small example project that reproduces the issue. The error happens in autotest_axs.c in line 71, a breakpoint is set for convenience. The additionally attached LabVIEW VI is used to operate as the ActiveX client and performs the necessary calls to reproduce the effect. Just build the CVI project in debug mode and start the VI while the CVI application is running.

 

For now I don't think I'm doing something wrong, maybe anybody at NI has an idea.

 

Thanks in advance!

Torsten

0 Kudos
Message 1 of 3
(3,237 Views)
Solution
Accepted by topic author Lenin
In the AutotestApplicationget_String function in file autotest.c, you should be using the CVI ActiveX library function CA_AllocateMemory to allocate the memory for the string. You are instead using the ANSI C malloc function. This allocated memory is later deallocated by calling calling CA_FreeMemory in function CaSrvrAutotestApplicationget_String in file autotest_axs.c. It is getting allocated in one memory manager, and deallocated in another.
0 Kudos
Message 2 of 3
(3,224 Views)

Thanks for the quick and helpful reply. Using CA_AllocMemory ()  indeed fixes the problem.

The only "bad taste" remaining here is the lack of documentation. I haven't found a note that there are two indepnedent memory managers.

 

But anyway, now it works. Thanks again!

Torsten

0 Kudos
Message 3 of 3
(3,196 Views)