贴出如下代码,请大家帮帮忙,(如果有个powerpoint实例运行的话代码执行正常,没有的话代码会在Open那儿出现异常)
{
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};VARIANT vResult;
OLECHAR FAR* szFunction;
BSTR bstrTemp;
IDispatch* pDispPresentations; DISPID dispid_Presentations;
DISPID dispid_Open; //Open a .ppt fileDISPID dispid_Quit; //Quit method of the Application object
// ******************** Start Automation ***********************//Initialize the COM libraries
::CoInitialize(NULL);// Create an instance of the ppt application and obtain the
// pointer to the application's IDispatch interface.
CLSID clsid;
CLSIDFromProgID(L"PowerPoint.Application", &clsid); IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER,
IID_IUnknown, (void**) &pUnk);
IDispatch* pDispApp;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);szFunction = OLESTR("Presentations");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,LOCALE_USER_DEFAULT, &dispid_Presentations);hr = pDispApp->Invoke(dispid_Presentations,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_PROPERTYGET,&dpNoArgs,&vResult,NULL,NULL);pDispPresentations = vResult.pdispVal;//Setup the DISPPARAMS for the Open method (2 arguments)
DISPPARAMS dpOpen;
VARIANT vArgsOpen[2];
dpOpen.cArgs=2;
dpOpen.cNamedArgs=0;
dpOpen.rgvarg=vArgsOpen;bstrTemp=::SysAllocString(OLESTR("c:\\test.ppt"));
vArgsOpen[1].vt=VT_BSTR;
vArgsOpen[1].bstrVal=bstrTemp;
vArgsOpen[0].vt= VT_BOOL;
vArgsOpen[0].boolVal=FALSE; szFunction=OLESTR("Open");
hr=pDispPresentations->GetIDsOfNames(IID_NULL,&szFunction,1,LOCALE_USER_DEFAULT,&dispid_Open);hr=pDispPresentations->Invoke(dispid_Open,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_METHOD,&dpOpen,NULL,NULL,NULL);
......}
{
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};VARIANT vResult;
OLECHAR FAR* szFunction;
BSTR bstrTemp;
IDispatch* pDispPresentations; DISPID dispid_Presentations;
DISPID dispid_Open; //Open a .ppt fileDISPID dispid_Quit; //Quit method of the Application object
// ******************** Start Automation ***********************//Initialize the COM libraries
::CoInitialize(NULL);// Create an instance of the ppt application and obtain the
// pointer to the application's IDispatch interface.
CLSID clsid;
CLSIDFromProgID(L"PowerPoint.Application", &clsid); IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER,
IID_IUnknown, (void**) &pUnk);
IDispatch* pDispApp;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);szFunction = OLESTR("Presentations");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,LOCALE_USER_DEFAULT, &dispid_Presentations);hr = pDispApp->Invoke(dispid_Presentations,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_PROPERTYGET,&dpNoArgs,&vResult,NULL,NULL);pDispPresentations = vResult.pdispVal;//Setup the DISPPARAMS for the Open method (2 arguments)
DISPPARAMS dpOpen;
VARIANT vArgsOpen[2];
dpOpen.cArgs=2;
dpOpen.cNamedArgs=0;
dpOpen.rgvarg=vArgsOpen;bstrTemp=::SysAllocString(OLESTR("c:\\test.ppt"));
vArgsOpen[1].vt=VT_BSTR;
vArgsOpen[1].bstrVal=bstrTemp;
vArgsOpen[0].vt= VT_BOOL;
vArgsOpen[0].boolVal=FALSE; szFunction=OLESTR("Open");
hr=pDispPresentations->GetIDsOfNames(IID_NULL,&szFunction,1,LOCALE_USER_DEFAULT,&dispid_Open);hr=pDispPresentations->Invoke(dispid_Open,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_METHOD,&dpOpen,NULL,NULL,NULL);
......}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货