DISPPARAMS dpNoArgs NULL NULL VARIANT vResult OLECHAR FAR szFunction B

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
VARIANT vResult;
OLECHAR FAR* szFunction;
BSTR bstrTemp;
IDispatch* pDispPresentations;
DISPID dispid_Presentations;
DISPID dispid_Open; //Open a .ppt file
DISPID 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);
DISPID dispid_SaveAs; //SaveAs method of the Document object
DISPID dispid_ActiveDoc; //ActiveDocument property of
//Application object
IDispatch* pDispActiveDoc; //ActiveDocument object
// Get IDispatch* for the ActiveDocument object
szFunction = OLESTR("ActivePresentation");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT,
&dispid_ActiveDoc);
hr = pDispApp->Invoke (dispid_ActiveDoc, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
&dpNoArgs, &vResult, NULL, NULL);
pDispActiveDoc = vResult.pdispVal;
//Set up the DISPPARAMS for the SaveAs method (11 arguments)
VARIANT vArgsSaveAs[11];
DISPPARAMS dpSaveAs;
dpSaveAs.cArgs = 11;
dpSaveAs.cNamedArgs = 0;
dpSaveAs.rgvarg = vArgsSaveAs;
BSTR bstrEmptyString;
bstrEmptyString = ::SysAllocString(OLESTR(""));
VARIANT vFalse;
vFalse.vt = VT_BOOL;
vFalse.boolVal = FALSE;
bstrTemp = ::SysAllocString(OLESTR("c:\\test2.ppt"));
vArgsSaveAs[10].vt = VT_BSTR;
vArgsSaveAs[10].bstrVal = bstrTemp; //Filename
vArgsSaveAs[9].vt = VT_I4;
vArgsSaveAs[9].lVal = 0; //FileFormat
vArgsSaveAs[8] = vFalse; //LockComments
vArgsSaveAs[7].vt = VT_BSTR;
vArgsSaveAs[7].bstrVal = bstrEmptyString; //Password
vArgsSaveAs[6].vt = VT_BOOL;
vArgsSaveAs[6].boolVal = TRUE; //AddToRecentFiles
vArgsSaveAs[5].vt = VT_BSTR;
vArgsSaveAs[5].bstrVal = bstrEmptyString; //WritePassword
vArgsSaveAs[4] = vFalse; //ReadOnlyRecommended
vArgsSaveAs[3] = vFalse; //EmbedTrueTypeFonts
vArgsSaveAs[2] = vFalse; //SaveNativePictureFormat
vArgsSaveAs[1] = vFalse; //SaveFormsData
vArgsSaveAs[0] = vFalse; //SaveAsOCELetter
//Invoke the SaveAs method
szFunction = OLESTR("SaveAs");
hr = pDispActiveDoc->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT,
&dispid_SaveAs);
hr = pDispActiveDoc->Invoke(dispid_SaveAs, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpSaveAs, NULL, NULL, NULL);
::SysFreeString(bstrEmptyString);
return FALSE;