Managing Global Data in ActiveX Applications
- Updated2023-02-21
- 1 minute(s) read
Managing Global Data in ActiveX Applications
Use the CA_ServerSetGlobalData, CA_ServerGetGlobalData, and CA_ServerReleaseGlobalData functions to manage any global data that your ActiveX functions access. For example, in a DAQ application the device number can be treated as global data. These functions ensure that the server’s threading model restrictions are properly enforced. As these functions cache and retrieve a 32-bit address, place all the global data in a structure and call CA_ServerSetGlobalData with the address of the structure. Make sure this call is in the main function of the module, after the Init function succeeds.
- DLL server—Call CA_ServerSetGlobalData in the DllMain DLL_PROCESS_ATTACH case.
- EXE server—Call CA_ServerSetGlobalData before calling RunUserInterface or any other function that processes events.
CA_ServerSetGlobalData caches the pointer that is passed in but does not make any copies of your data. When you need to access the global data, you must call CA_ServerGetGlobalData to acquire the cached pointer. After using the global data, you must call CA_ServerReleaseGlobalData to relinquish the cached pointer back to the LabWindows/CVI ActiveX Library. Every function that calls CA_ServerGetGlobalData successfully also must call CA_ServerReleaseGlobalData. Internally, CA_ServerGetGlobalData acquires a lock, and CA_ServerReleaseGlobalData releases the lock. By using the global data functions, you can avoid providing threading synchronization, which requires the use of LabWindows/CVI multithreading functions or Windows synchronization functions. Advanced users can choose not to use the global data functions and instead manage their global data using a synchronization mechanism based on the COM threading model of their server.
Refer to the CA_ServerSetGlobalData topic for example code demonstrating the use of the global data functions.