Admin Production ni-theme
Current Publication

CA_VariantConvertToType

LabWindows/CVI

CA_VariantConvertToType

HRESULT CA_VariantConvertToType (VARIANT *variant, unsigned int desiredType, void *convertedValue);

Purpose

Converts a value in a variant to a variable with a data type you specify. This can help you when you are uncertain about the data type a variant stores and when you need to work with a particular data type.

CA_VariantConvertToType converts all the fundamental types, such as numeric, string, DATE, CURRENCY, and so on. It converts from a pointer to a value by dereferencing the pointer. It cannot convert to a pointer type, and it cannot convert to or from array types unless the desiredType is exactly the same as the type in the variant.

Upon success, CA_VariantConvertToType frees the contents of the variant parameter, marks it as empty, and sets the type to VT_EMPTY.

Note   If you convert to an array type, the function returns a safe array, not a C-style array.

Parameters

Input
Name Type Description
desiredType unsigned int Type to convert the variant value to.

desiredType can be any of the fundamental data types for variants, safe arrays, and properties except CAVT_EMPTY or CAVT_NULL.

You also can use the CAVT_ARRAY modifier with any of the types. If you do, the type you specify must match exactly the type in the variant, and the function returns a safe array, not a C-style array.

If the type of the converted value is char*, CAObjHandle, BSTR, LPDISPATCH, LPUNKNOWN, or an array of any type, you must call the appropriate function to free the convertedValue when you no longer need it.
Output
Name Type Description
variant VARIANT Variant that contains the value to convert.

On success, CA_VariantConvertToType frees the variant contents and marks the variant as empty.
convertedValue void * The converted value.

Pass the address of a variable large enough to hold the converted value.

If the type of the converted value is char*, CAObjHandle, BSTR, LPDISPATCH, LPUNKNOWN, or an array of any type, you must call the appropriate function to free convertedValue when it is no longer needed.

Data Type Function to Free Converted Value
char * CA_FreeMemory
CAObjHandle CA_DiscardObjHandle
BSTR CA_FreeBSTR
LPUNKNOWN convertedValue->lpVtbl->Release(convertedValue)
LPDISPATCH convertedValue->lpVtbl->Release(convertedValue)
any type | CAVT_ARRAY CA_SafeArrayDestroy
Note    CAObjHandles created by this function do not support multithreading and use LOCALE_NEUTRAL.

To use different values for multithreading support and locale you can use either of the following approaches:

Return Value

Name Type Description
status HRESULT A value indicating whether an error occurred. Negative error codes indicate function failure.

Error codes are defined in CVIversion\include\cviauto.h and <Program Files>\National Instruments\Shared\MSDTRedistributables\SDKHeaderFiles\8.1\winerror.h. The LabWindows/CVI ActiveX Library explicitly returns error codes. Other error codes in winerror.h are generated by ActiveX servers and passed on to you by the LabWindows/CVI ActiveX Library.

You can use CA_GetAutomationErrorString to get the description of an error code or CA_DisplayErrorInfo to display the description of the error code.

Additional Information

Library: ActiveX Library

Include file: cviauto.h

LabWindows/CVI compatibility: LabWindows/CVI 5.0 and later