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

Re: Another CreateObject C# question by Jason

Jason
Fri Nov 11 15:52:39 CST 2005

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

Homer wrote:
> 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