c# - Passing strongly typed arguments in .NET COM interop -
i have 2 .net classes exposed via com interop - let's foo , bar, , need pass argument of type foo method defined in bar. this:
[comvisible(true)] public class foo { // whatever } [comvisible(true)] public class bar { public void method(foo fff) { // fff } }
when run following vbs (using cscript.exe):
set foo = createobject("testcsproject.foo") set bar = createobject("testcsproject.bar") call bar.method(foo)
i error:
d:\test.vbs(3, 1) microsoft vbscript runtime error: invalid procedure call or argument: 'bar.method'
however, if change method declaration this:
public void method(object o) { foo fff = (foo)o; // fff }
everything works. tried magic interfaces, attributes, etc. no luck far.
any insight?
many thanks
make sure, define guid attribute, necessary if make queryinterface (vb probably). have generate new unique guid every comvisible class.
[guid("77777777-3333-40df-9c0d-2b580e7e1f3b")] [comvisible(true)] public class foo { }
then recommend write interfaces com objects, , set classinterface none, no internals revealed. typelibrary cleaner way.
[guid("88888888-abcd-458c-ab4c-b14af7283a6b")] [comvisible(true)] public interface ifoo { } [classinterface(classinterfacetype.none)] [guid("77777777-3333-40df-9c0d-2b580e7e1f3b")] [comvisible(true)] public class foo : ifoo { }
Comments
Post a Comment