IDispatch::GetIDsOfName() and IDispatch::Invoke() Help
- From: heyji2@xxxxxxxxx
- Date: Thu, 08 Nov 2007 11:13:31 -0000
Hi,
I am trying to automate a Excel *** from a Windows Froms
application. I know it has been done millions of times, I have read a
lot of things in newsgroups, and in msdn, but I am stuck here. Would
somebody comment my code and help me to go further ?
Thank you.
AG.
IRunningObjectTable * prot;
IEnumMoniker * penumMoniker=NULL;
IUnknown * punkObject;
IMoniker * mon;
ULONG Fetched=0;
HRESULT hr;
if(GetRunningObjectTable(0,&prot)!=S_OK)
{
toolStripStatusLabel1->Text = "Error, could not get a pointer
on ROT";
return;
}
toolStripStatusLabel1->Text = "ROT OK";
if(prot->EnumRunning(&penumMoniker)!=S_OK)
{
toolStripStatusLabel1->Text = "Error, could not Enumerate
through the ROT";
return;
}
penumMoniker->Reset();
while(penumMoniker->Next(1,&mon,&Fetched)==S_OK)
{
IBindCtx * pCtx;
if(CreateBindCtx(0,&pCtx)!=S_OK)
{
toolStripStatusLabel1->Text = "Error, Could not Bind
Ctx";
return;
}
LPOLESTR Name;
for(int i=0;i<Fetched;i++)
{
// here the Name variable shows the path to my excel
*** : "file://C:\test\testExcel.xls"
if(mon[i].GetDisplayName(pCtx,NULL,&Name)!=S_OK)
{
toolStripStatusLabel1->Text = "Error in
GetDisplayName";
}
}
pCtx->Release();
hr = prot->GetObject(&mon[0],&punkObject);
if(!FAILED(hr))
{
hr = prot->IsRunning(&mon[0]);
if(!FAILED(hr))
{
break;
}
}
}
IDispatch * pDisp;
hr = punkObject->QueryInterface(IID_IDispatch,(void**)&pDisp);
if(FAILED(hr))
{
toolStripStatusLabel1->Text = "Error querying the Interface";
}
DISPID id;
LPOLESTR Name=L"Excel";
hr = pDisp->GetIDsOfNames(IID_NULL,&Name,1,LOCALE_USER_DEFAULT,&id);
if(FAILED(hr))
{
// I always get here. I am not sure the Name "Excel" is
correct or what to put here ? "Excel.Application" ,...?
toolStripStatusLabel1->Text = "GetIDsOfNames failed";
}
.
- Follow-Ups:
- Re: IDispatch::GetIDsOfName() and IDispatch::Invoke() Help
- From: Igor Tandetnik
- Re: IDispatch::GetIDsOfName() and IDispatch::Invoke() Help
- Prev by Date: Systemwide out-of-process COM servers walkout
- Next by Date: Re: IDispatch::GetIDsOfName() and IDispatch::Invoke() Help
- Previous by thread: Systemwide out-of-process COM servers walkout
- Next by thread: Re: IDispatch::GetIDsOfName() and IDispatch::Invoke() Help
- Index(es):