1

I have written a class library (.dll) in C#, which is called from a 3rd-party .exe. The .exe calls a method in my .dll, passing a COM Object to my method. For various reasons, I don't have access to an equivalent class definition of this COM Object, but I am able to discover its public methods and properties, using this handy DispatchUtility class tool. I hoped to create an extern class definition, so I can access those members, but as I discovered, C# does not allow that.

What is the best/"proper" way to access these class members?

Conrad
  • 2,197
  • 28
  • 53
  • Your pronouns and thises and thats are all mixed up and it's hard to comprehend what you are asking. What I think you need to do is just get the IDispatch interface for the COM object and call Invoke from it. Look at Hans answer in this post: http://stackoverflow.com/questions/8068449/calling-a-member-of-idispatch-com-interface-from-c-sharp – Joseph Willcoxson Apr 06 '17 at 14:07
  • @JoeWillcoxson I'd be happy to edit for clarification - what are the first couple things which are ambiguous? I will take a look at that Q&A as well. – Conrad Apr 06 '17 at 14:16

1 Answers1

0

If you know the method names and argument types, you can just use dynamic.

dynamic o = theComObject;
o.SomeMethod(arg1, arg2, arg3);
var v = o.SomeProperty;
Michael Gunter
  • 12,528
  • 1
  • 24
  • 58