Invokes a method on a .NET object instance.
While you can often call methods directly on an instance, the COM Interop mechanism has many limitations for calling .NET methods that have multiple overloads, have value, generic or incompatible types as parameters.
InvokeMethod() can be used when the method call will not work directly.
This method is limited to a maximum of 10 parameters. If you need more parameters use InvokeMethod_ParameterArray() instead.
Invoked method is fixed up so that arrays are passed/returned as ComArray instances, Guids as ComGuid.
An object instance on which to invoke the method
The name of the method to call on the Instance.
The method can also be a 'nested' method name like "ValidationErrors.ToHtml". Use this syntax if a type along the hierarchy is not accessible by FoxPro (Value type, Generic Type etc.)
Optional parameters up to 24
Parameter passing errors, or errors that occur inside of the .NET code that you are calling cause an Exception in FoxPro code.
If you get Invalid Method or Method not found errors most likely you are calling the method with missing or invalidly typed parameters.
In some cases you may have to explicitly coerce parameter types by using the VFP CAST() function. This is especially true for numeric values since VFP numbers are typically passed as double or int depending on the existance of decimals. For example, decimal values need CAST(1.11 as Currency) or CAST(10 as int).
You can also use the ComValue Class to explicitly force parameter types to specific types, including types that you cannot set directly from FoxPro such as Single, Long, Byte, Guid, DbNull and numerous others.
To pass ByRef/Ref parameters use ComValue objects instead of plain parameter values. ComValue parameters will always be updated after returning from a method call.
*** Simple Method Invokation: loNet = loBridge.Createinstance("Westwind.WebConnection.TypePassingTests") ? loBridge.InvokeMethod(loNet,"HelloWorld","Rick") *** Note this is the same as: loNet.HelloWorld("Rick") *** Pass ByRef parameters and return values: *** Create ComValue objects for each parameter loInt = loBridge.CreateComValue(INT(10)) loString = loBridge.CreateComValue("Hello World.") loDecimal = loBridge.CreateComValue(CAST( 5.22 as Currency)) ? "Original:" ? loInt.Value, loString.Value, loDecimal.Value lobridge.InvokeMethod(loNet,; "PassByReference",; loInt,loString,loDecimal) *** Look at the result values ? "Updated:" ? loInt.Value, loString.Value, loDecimal.Value
See also:Class wwDotNetBridge
Comment or report problem with topic