Click here to Skip to main content
15,798,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
Ive been trying to develop a COM Client application, but without success. My goal is to create an application that can open reports in Cognos Impromptu. Ive got Cognos Impromptu installed on this machine and im using Visual Studio 2008 to develop the client.
I created my project as a consoleapplication in Visual Studio. Next, I added the Impromptu Client Reference via Project > Add Reference > COM. All works fine till now, Visual Studio creates my COM Wrapper dll and adds it to the bin/debug folder.
But when I trry to run my program, it gives me the following Exception:
Unable to cast COM object of type 'ImpromptuClient.ImpromptuApplicationClass' to
interface type 'ImpromptuClient.IAppAuto'. This operation failed because the Qu
eryInterface call on the COM component for the interface with IID '{2F835754-FB4
F-11CF-8E5F-00401C60350D}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Press any key to continue . . .
The code I use is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.InteropServices;
using ImpromptuClient;
namespace TestApp2
	class Program
		static void Main(string[] args)
				ImpromptuApplicationClass app = new ImpromptuApplicationClass();
                  	app.Visible(true); //<-- This causes the Exception
			catch (Exception e)
I can create an instance of tje ImpromptuApplicationClass. I can also call methods like GetType() (Which is ImpromptuApplicationClass). But when I call the method Visible, the mentioned Exception is thrown.
Another thing I tried is using the Activator.CreateInstance() function, but also without succes:
Type oType = Type.GetTypeFromProgID("CognosImpromptu.Application");
Object obj = Activator.CreateInstance(oType);
ImpromptuApplication app = obj as ImpromptuApplication //app = null
ImpromptuApplication app2 = (ImpromptuApplication)obj;//Throws the previously mentioned exception
The last thing I tried, is to call methods via Reflection. This kinda worked, but when I had opened a catalog, I needed to open a report after that. That worked too, but the function OpenReport() returns an ImpromptuReport object. I need to call the method ExportExcel() on the report object and therefore the returnvalue of the OpenCatalog method needs to be casted to an ImpromptuReport object first. Which, as you might expect, also throws the previously mentioned exception.
ImpromptuApplication MyApplication = new ImpromptuApplication();
MyApplication.GetType().InvokeMember("Visible", System.Reflection.BindingFlags.InvokeMethod, null, MyApplication, new object[] { "true" });
object[] catArgs = { @"D:\", "catalogname", "cataloguser", "username", "pwd" };
MyApplication.GetType().InvokeMember("OpenCatalog", System.Reflection.BindingFlags.InvokeMethod, null, MyApplication, catArgs);
object[] reportArgs = { @"D:\reportfilename.imr" };
ImpromptuReport report = null;
report = (ImpromptuReport)MyApplication.GetType().InvokeMember("OpenReport", BindingFlags.InvokeMethod, null, MyApplication, reportArgs);
report.GetType().InvokeMember("CloseReport", BindingFlags.InvokeMethod, null, null, null);	
Ive been trying to get this to work for the past couple of days, but unfortunatly without any succes. Does any of you guys have an idea what Im doing wrong?
Thanks in advance!
Jason C Daniels 17-Jan-11 1:01am    
If Cognos publishes an API to their COM interface, have you tried reading that? If so, have you contacted Cognos' technical support line?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900