Cannot create instance of the interface 'Application'

  • Thread starter Thread starter Marcus Eklund
  • Start date Start date
M

Marcus Eklund

Hi Marcus,

I don't think you want to create a "new" application. You probably just
want to get a pointer to the existing application. I'm not sure how to do
this in csharp, but here is some C++ code from an Outlook add-in to
accomplish this:

HRESULT BSAddIn::GetOutlookApp(IExchExtCallback *pmecb,
Outlook::_ApplicationPtr &rOLAppPtr)
{
try
{
IOutlookExtCallback *pOutlook = NULL;
HRESULT hRes = pmecb->QueryInterface(IID_IOutlookExtCallback,(void **)
&pOutlook);
if (pOutlook)
{
IUnknown *pUnk = NULL;
pOutlook->GetObject(&pUnk);
LPDISPATCH lpMyDispatch;
if (pUnk != NULL)
{
hRes = pUnk->QueryInterface(IID_IDispatch, (void **)
&lpMyDispatch);
pUnk->Release();
}
if (lpMyDispatch)
{
OLECHAR * szApplication = L"Application";
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
DISPID dspid;
VARIANT vtResult;
lpMyDispatch->GetIDsOfNames(IID_NULL, &szApplication, 1,
LOCALE_SYSTEM_DEFAULT, &dspid);
lpMyDispatch->Invoke(dspid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dispparamsNoArgs, &vtResult, NULL, NULL);
lpMyDispatch->Release();

rOLAppPtr= vtResult.pdispVal;
return S_OK;
}
}
}
catch(...)
{
}
return S_FALSE;
}

Mark
http://www.email-announcer.com
 
Hi Mark,

Thanks for the answer.
I just solved it, a bit father down in that webpage i was reading, they
said what to use instead of Application. You had to use ApplicationClass
and it worked fine.

/Marcus
 
Back
Top