Another CreateObject C# question

G

Guest

My question is how can I in C# call methods on a COM object without having an
interface or a RCW referenced. I have a COM component that I cannot import
into .NET, it throws a bunch of errors.
In VB.NET I was able to do the following:
Dim instance As Object
impromtuApplication = CreateObject("Impromptu.Application")
impromtuApplication.DoSomething("Paramters")

In C# I have somewhat the equivelant code:
string progId = "CognosImpromptu.Application";
Type comType = Type.GetTypeFromProgID(progId, true);
appInstance = Activator.CreateInstance(comType);
appInstance.DoSomething("Paramters"); // this line fails because it
says no method like this exists

So I know I have to cast this object to an Interface or COM object, is
there anyway to do this WITHOUT having the RCW or Interface. I don't want to
start writing VB.NET code to get this to work <shivers>

Thanks in advance
 
J

Jason Newell

Homer,

Read up on .NET Reflection. Not ideal but it answers your question.

object[] args = null; // Could be populated depending on Method Signature.
yourobject.GetType().InvokeMember("MethodName",
System.Reflection.BindingFlags.InvokeMethod, null, yourobject, args);

Jason Newell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top