Dear Sirs,
i try to call a COM object via InvokeMember() - which works for the
simple case (in parameter).
But i don't have an idea how to use soemthing like ""[out] VARIANT* ".
How can i pass an array by ref to a COM Object ?
Attached are the .cs code and the typelib. The *interesting* variable is
"quantityTotal".
best regards,
goran
----- typelib -----
// typelib filename: MyApp.tlb
[
uuid(06688AF1-07BE-11D7-AABF-00D0B7B2802B),
version(3.0),
helpstring("MyApp")
]
library MyAppTypLib
{
// TLib : // TLib : OLE Automation :
{00020430-0000-0000-C000-000000000046}
importlib("stdole32.tlb");
// Forward declare all types defined in this typelib
dispinterface INTER_AP1;
dispinterface INTER_AP2;
[
uuid(06688AF2-07BE-11D7-AABF-00D0B7B2802B),
helpstring("Dispatch Interface")
]
dispinterface INTER_AP1 {
properties:
methods:
[id(0x00000010)]
short function10 (
[in] BSTR equipmentName,
[out] long* recnum,
[out] VARIANT* quantityTotal );
...
};
[
uuid(06688AF3-07BE-11D7-AABF-00D0B7B2802B),
helpstring("Dispatch Interface")
]
dispinterface INTER_AP2 {
properties:
methods:
...
};
[
uuid(06688AF4-07BE-11D7-AABF-00D0B7B2802B),
helpstring("Coclass of MyApp")
]
coclass my_coclass {
[default] dispinterface INTER_AP2;
dispinterface INTER_AP1;
};
};
----- C# Code -----
using System;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
Type objTypeMyApp = Type.GetTypeFromProgID("OLEDemo");
object objMyAppLateBound = Activator.CreateInstance(objTypeMyApp);
object myAppObj = objTypeAirline.InvokeMember("MyApplication",
BindingFlags.Default | BindingFlags.GetProperty,
null,
objAirlineLateBound,
new object[]{});
System.Int32 recnum = new System.Int32(); // Is this corrent ???
... quantityTotal = ... // HOW TO DEFINE THIS ???????
ParameterModifier pm1 = new ParameterModifier(2);
pm1[0] = true;
pm1[1] = false;
ParameterModifier pm2 = new ParameterModifier(2);
pm2[0] = false;
pm2[1] = true;
ParameterModifier pm3 = new ParameterModifier(2);
pm3[0] = false;
pm3[1] = true;
object[] arrayInputEq = { "Equipment_01", recnum, quantityTotal };
object funcObj = myAppObj.GetType().InvokeMember("function10",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
myAppObj,
arrayInputEq, new ParameterModifier[]{pm1, pm2, pm3}, null, null );
Console.ReadLine();
}
}
}
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.