4

I instantiate a COM Object, then invoke a method.

ActiveXComponent comp = new ActiveXComponent("MyDll.MyClass");

String argument1 = "test1";
String argument2 = "test2";

Variant[] arguments = { new Variant(argument1), new Variant(argument2) };

comp.invoke("myMethod", arguments)

Assuming MyDll has a method called

myMethod(String s1, String s2) 

it works fine.

Now, what if I have a Method

myMethod(String s1, ReturnDeletedModeEnum enum)

with an enum defined in MyDll?

I need to pass the enum to the method somehow, but I don't know how to access it.

I tried getting the Enum as ActiveXComponent,

new ActiveXComponent("MyDll.ReturnDeletedModeEnum");

which (not surprisingly) didn't work:

com.jacob.com.ComFailException: Can't get object clsid from progid

I tried finding some more documentation about Jacob, because there seem to be Enum-specific classes, but I haven't found any explanation on how to use them.

Jonas Eicher
  • 1,413
  • 12
  • 18

1 Answers1

0

I ran into the same uncertainty when I needed to call a method with an Enummeration parameter. I couldn't find much documentation - JACOB or otherwise.

I did stumble across a helpful post on the subject which says the values ... correspond to internally stored numbers and An enumeration in VBA is always of data type Long.

Armed with that and the MS Documentation for my particular Enumeration, I gave this a try ...

Dispatch.call(oDocuments, "Open", fileIn, ... ,  new Variant(1L));

And it worked!

I'm sure there's a way to get actual "Enumeration" data structures, but this was good enough for me.

Jacob Zwiers
  • 1,092
  • 1
  • 13
  • 33