Hi,
I'm using a COM object which has a method with 5 arguments, 3 of them being optional (below).
---------------
COM Object method
objLibrary.CreateObject(ObjType, ClassIdent, [Option], [OptionEx1], [OptionEx2])
Parameters:
ObjType - idmObjectType
ClassIdent - Variant.
Option - Optional. Variant.
OptionEx1 - Optional. Variant.
OptionEx2 - Optional. Variant. Not implemented.
---------------
My code:
IDMObjects.Document objDoc;
objDoc = (IDMObjects.Document) (objLibrary.CreateObject(IDMObjects.idmObjectType.idmObjTypeDocument, objClsDesc, variant1, variant2, variant3));
-------------------In VB and C++, I can ignore the 3 optional arguments ie. CreateObject( arg1, arg2), but in C#.NET I need to supply 5 arguments. I tried putting null, empty string, zero into the optional arguments (variant1, variant2, variant3) but I keep on getting "Bad Variable" error.
I also tried declaring a variable of type Object:
Object variant1 = new Object()
and feed that into the optional arguments, but didn't work either.
Could anyone please help me?
Thank you so much in advanced.
Regards,
Tina
AlanPosted Aug 2, 2007, 6:41 AM
Munir Shaikh is correct that the Variant datatype is not used in .NET; System.Object is used instead.
However, when calling methods which require optional arguments from C#, this usually works (I've assumed all three arguments are passed by value - precede by 'ref' otherwise):
object optional = Type.Missing;
objDoc = (IDMObjects.Document) (objLibrary.CreateObject(IDMObjects.idmObjectType.idmObjTypeDocument, objClsDesc, optional, optional, optional));
Munir ShaikhPosted Aug 2, 2007, 2:44 AM
Hi,
Just try doing
Object variant1; do not create new object
As per my knowledge Varient datatype is not available in vb.net.OPtion Explisit is available.I think Option Explicit is True by default which should be true in C#
so instead making Dim someVariable try
Object variant1;
Possibly will help you.
>>Munnamax