Opc.Ua.Com.ComUtils.GetVARIANTs C# (CSharp) Method

GetVARIANTs() public static method

Unmarshals an array of VARIANTs as objects.
public static GetVARIANTs ( IntPtr &pArray, int size, bool deallocate ) : object[]
pArray System.IntPtr
size int
deallocate bool
return object[]
		public static object[] GetVARIANTs(ref IntPtr pArray, int size, bool deallocate)
		{
			// this method unmarshals VARIANTs one at a time because a single bad value throws 
			// an exception with GetObjectsForNativeVariants(). This approach simply sets the 
			// offending value to null.

			if (pArray == IntPtr.Zero || size <= 0)
			{
				return null;
			}

			object[] values = new object[size];

			IntPtr pos = pArray;

			for (int ii = 0; ii < size; ii++)
			{
				try 
				{
					values[ii] = Marshal.GetObjectForNativeVariant(pos);
                    values[ii] = ProcessComValue(values[ii]);
					if (deallocate) VariantClear(pos);
				}
				catch (Exception)
				{
					values[ii] = null;
				}

				pos = (IntPtr)(pos.ToInt64() + VARIANT_SIZE);
			}

			if (deallocate)
			{
				Marshal.FreeCoTaskMem(pArray);
				pArray = IntPtr.Zero;
			}

			return values;
		}	

Same methods

ComUtils::GetVARIANTs ( object values, bool preprocess ) : IntPtr