Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
26 ratings:
 3.11 out of 5     Rate this Document

What Are the Variant, SafeArray, and BSTR Data Types

Primary Software: LabWindows/CVI Development Systems>>Full Development System
Primary Software Version: 8.1.1
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems>>LabVIEW Professional Development System

Problem:
What is a Variant data type? What is a SafeArray data type? What is a BSTR data type? Why are these needed?

Solution:
You will come across these data types frequently when communicating via ActiveX/COM.

A "Variant" is essentially a universal data type. It can contain any kind of information internally (i.e., it can represent any data type), along with some information about what data type the information belongs to; it is a general purpose, package data type. Think of a Variant as something that can represent every possible data type, but it separates the data itself the type information into individual pieces of the "package".

A BSTR is a basic string type that is simply another method for storing character string information (different than a NULL-terminated ASCII string). A BSTR stores characters in a UNICODE format. The first two bytes in the BSTR represent the length of the string. The actual data string comes after these first two bytes.

Finally, a SafeArray is an array type that contains user-protection information, together with the actual data. Think of a SafeArray as a normal C array, but it has additional information on the size of the array (i.e., the number of elements in the array) included in the actual data structure.

For additional information, refer to the attached Word document.

Related Links:
KnowledgeBase 24599KQT: How Do I Extract Information from a SAFEARRAY in Microsoft Visual C++?
KnowledgeBase 19EG81U0: What Do I Wire to an ActiveX Variant Parameter on a Property or Invoke Node?
KnowledgeBase DIRECT-3S8RM7: How Do I Convert ActiveX Variant Data to a Data Type That Can Be Used in LabVIEW?

Attachments:


Information on Variants and SafeArrays.doc


Report Date: 05/06/1998
Last Updated: 09/28/2007
Document ID: DIRECT-3U8U26

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit