Passing a VARIANT by ref to a COM object 
Author Message
 Passing a VARIANT by ref to a COM object

Hi!

i'm trying to call a COM object with InvokeMember(). For simple cases it
work's fine.

But i have no idea how this would work with an "[out] VARIANT* "
parameter.

How is it possible in C# to pass an Array by reference to a COM object ?

I attached part of the typelib and the C# code (the affected variable is
named "quantityTotal").

Any ideas ?

thanx,
hal

----- Type Lib -----

[
  uuid(06688AF2-07BE-11D7-AABF-00D0B7B2802B),
  helpstring("Dispatch Interface")
]
dispinterface MyApplication {
    properties:
    methods:
 ...

        [id(0x00000010)]
        short function10 (
                        [in] BSTR equipmentName,
                        [out] long* recnum,
                        [out] VARIANT* quantityTotal );

 ...

Quote:
};

----- 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();
   ... 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();
  }
 }

Quote:
}



Tue, 24 May 2005 05:50:41 GMT  
 Passing a VARIANT by ref to a COM object
Hermann,

The code looks correct to me. Have you tried to just pass in null for
quantityTotal, and then after the call retrieve it from
arrayInputEq[2]?

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Tue, 24 May 2005 07:02:35 GMT  
 Passing a VARIANT by ref to a COM object

Quote:

> Hermann,

> The code looks correct to me. Have you tried to just pass in null for
> quantityTotal, and then after the call retrieve it from
> arrayInputEq[2]?

Yes, i did. The result was a System.Reflection.TargetInvocationException
:((

A completely different question. Why isn't it possible to access a COM
object with this RCW-DLL for dispinterfaces / late binding ?

cu,
hal



Tue, 24 May 2005 16:34:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. passing objects from VB as VARIANT to COM server object failing

2. passing objects from VB as VARIANT to COM server object failing

3. Newbie COM Interop: passing null ref object to a method

4. Passing COM object pointers through VARIANT from ActiveX component

5. passing COM object pointers to another COM object in ATL

6. Passing COM objects as parameters to other COM objects

7. Passing COM objects as parameters to other COM objects

8. ExecutionEngineException occurs when passing ref object as 0/NULL from C++

9. using the ref keyword when passing objects

10. passing objects by VAL not REF ?

11. Unable to pass a ref object as a parameter to a property

12. passing objects ref

 

 
Powered by phpBB® Forum Software