Class ComValue

ComValue allows you to create .NET objects that can be passed to indirectly called wwDotnetBridge methods via SetProperty, InvokeMethod, CreateInstance and ComArray.AddItem. Use ComValue when the type that needs to be passed or assigned is of a type that cannot be marshalled through FoxPro, or to assign/pass types that have are not directly supported by the FoxPro type system. You can also use these when you get .NET overload mapping errors (Method or Constructor not found) when the COM type conversions won't uniquely identify a .NET signature.

Examples of unsupported types are Long, Single, Decimal, Guid, Byte, DbNull and Char and Value types that need to be passed by parameter. Examples of values that might not map are Enums, Value types and Generic types.

How it works

ComValue works by creating an object inside of .NET and assigning a value on this object through the various access methods that can perform the proper type translations from the FoxPro value. Then, rather than passing the real value, using indirect methods you can pass the ComValue object in place of the questionable parameter. wwDotnetBridge then fixes up the parameter and passes the actual .NET value as a parameter to the method parameter or property value.

ComValue objects must be used with one of the following wwDotnetBridge methods to assign a value:

  • SetProperty/SetPropertyEx()
  • InvokeMethod()
  • CreateInstance() (constructors with parameters)
  • ComArray.AddItem()

You can't pass ComValue() to .NET methods directly, because they'll have no idea what the COM value represents. wwDotnetBridge performs special processing on the ComValue instance by extracting the value and then assigning it to the parameter or property at runtime.

Using ComValue allows you to keep a value inside of .NET without ever passing the actual value to FoxPro. This makes it possible to work with types that COM and FoxPro don't support as well providing exactly typed values to assign in method overloads.

Simple type conversion:

*** Create .NET Object instance
loNet = loBridge.CreateInstance("MyApp.MyNetObject")

*** Convert the 'unsupported' parameter type
LOCAL loVal as Westwind.WebConnection.ComValue
loVal = loBridge.CreateComValue()

*** Call method that takes Int16 parameter

ComValue caching for Method and Property Invocation

This class also supports setting a ComValue from properties and method results. This is useful if you have a method or property that uses a type inaccessible via COM (like strongly typed or subclassed dataset objects for example). In this case you can call the SetValueXXX methods to fill the ComValue structure and then use this ComValue in InvokeMethod, SetProperty calls which automatically pick up this ComValue object's underlying .NET type.

*** Create an array of parameters (ComArray instance)
loParms = loBridge.CreateArray("System.Object")
loParms.AddItem("Error Message")

*** Create a ComValue structure to hold the result: a DataSet
LOCAL loValue as Westwind.WebConnection.ComValue
loValue = loBridge.CreateComValue()

*** Invoke the method and store the result on the ComValue structure
*** Result from this method is DataSet which can't be marshalled properly over COM
? loValue.SetValueFromInvokeMethod(loService,"Login",loParms)

*** This is your raw DataSet
*? loValue.Value   && direct access won't work  because it won't marshal

*** Now call a method that requires the DataSet parameter

The jist of this is that the DataSet result is never passed through FoxPro code, but is stored in ComValue and then that ComValue is used as a parameter in the InvokeMethod call. All indirect execution methods (InvokeMethod,SetProperty etc.) understand ComValue and use the Value property for the parameter provided.

public class ComValue : object

Class Members




Returns a GUID stored in the Value properties.





Retrieves the fixed up value from the .Value property. The call is returned by calling .GetProperty() to retrieve the value which automatically converts problem types to the appropriate wrapper types (ie. Array/Collections to ComArrays, DbNulls to Nulls etc.).



Creates a new GUID and stores it in the Value.



Returns a byte value which is similar to Int16.

public void SetByte(object value);


Converts a FoxPro string or number to a .NET char value on the Value structure.

o.ComValue.SetChar(object val)


Sets a DbNull value from FoxPro. DbNull is a value type and can't be accessed directly in FoxPro.



Sets a Decimal value. Turns any FoxPro numeric value to a .NET decimal value.

This can actually be done in FoxPro explicitly with CAST(val as Currency) but this method can be used with pre-VFP 9 and is used internally to convert numerics to decimal.

public void SetDecimal(object val);


Allows you to create an Enum value that can be passed as a parameter.

o.ComValue.SetEnum(string enumString)


Sets the value to a .NET Guid by passing in either a GUID string, a ComGuid object, or a null (which creates a new Guid).

o.ComValue.SetGuid(object value)


Sets a Short value which is not supported in Visual FoxPro

public void SetInt16(object val);


Sets a Int64 value from a FoxPro numeric value. Since FoxPro doesn't have a cast to 64 bit values natively you can use decimal or float values in Fox or 32 bit integers.

public void SetInt64(object val);


Turns a FoxPro number to a Long 64 bit integer value in .NET. Note that FoxPro doesn't support casting to a 64 bit value, so you can pass a 32 bit integer or numbers that are decimal or floats to this function to achieve 64 bit Long values.

public void SetLong(object val);


Sets the value of this object to a Single based on a FoxPro number passed in.



Sets the value of this object to a .NET Single/float based on a FoxPro number passed in.



Sets a 32 bit UInt value on the Value property.

o.ComValue.SetUInt34(object val)


Sets a 64 bit unsigned integer value from a FoxPro number.

o.ComValue.SetUInt64(object val)


This method creates an instance of a generic type on the ComValue structure by allowing you to specify a generic type name, the generic type parameters (as a ComArray) and optional constructor parameters (as a ComArray.)



Allows setting of the Value property from the result of an object instantiation.

Useful when instantiating types that can't be accessed in VFP such as Generic types or Value types. Using this mechanism you can create an instance of the type.

o.ComValue.SetValueFromCreateInstance(string typeName,ComArray parms)


o.ComValue.SetValueFromEnum(string enumType, string enumKeyName)


Sets the Value property from a method call that passes it's positional arguments as an array.

Note that the array of parameters must be passed in as a COM Array.

public void SetValueFromInvokeMethod(object objectRef,     string method,     ComArray parms);


Sets the Value property from a method call that passes it's positional arguments as an array.

Note that the array of parameters must be passed in as a COM Array.

public void SetValueFromInvokeMethod(string typename,     string method,     ComArray parms);


Sets the Value property from a property retrieved from .NET Useful to transfer value in .NET that are marshalled incorrectly in FoxPro such as Enum values (that are marshalled as numbers).

public void SetValueFromProperty(object objectRef,     string property);


Sets the value property from a static property retrieved from .NET. Useful to transfer value in .NET that are marshalled incorrectly in FoxPro such as Enum values (that are marshalled as numbers)

public void SetValueFromStaticProperty(string typeName,     string property);


o.ComValue.SetValueFromSystemConvert(string method, object value)


Returns the value of contained ComValue instance value as a string.

Same as loComValue.Value.ToString() but doesn't require the implicit InvokeMethod() call.



Internally this value is set by the various SetXXX methods. It's of type objcect but set to the appropriate .NET subtype.


Namespace: Westwind.WebConnection
Assembly: wwdotnetbridge.dll

© West Wind Technologies, 1996-2019 • Updated: 12/23/15
Comment or report problem with topic