none
Type MisMatch exception thrown when using ExportAsFixedFormat in PowerPoint2010 RRS feed

  • Question

  • Hello,

    In the below code there is a TypeMisMatch exception is being thrown using latebindind but
    in early binding ExportAsFixedFormat is working fine. Please give me the solution why it is not working in latebinding.

    Thanks
    Karthi

    VARIANT vtOptional, vtFileName ,varFileType,varOutputFileName;
    vtOptional.vt = VT_ERROR;
    vtOptional.scode = DISP_E_PARAMNOTFOUND;
    VARIANT result;
    VariantInit(&result);
    
    VariantInit(&varFileType);
    varFileType.vt = VT_I4;
    varFileType.lVal = 2;
    				
    VariantInit(&varOutputFileName);
    varOutputFileName.vt = VT_BSTR;
    varOutputFileName.bstrVal = SysAllocString(L"D:\\Output.pdf");
    
    hr=InvokeMember(DISPATCH_METHOD, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&result, 
    							pdispPresentation, 
    							L"ExportAsFixedFormat", 
    							16 // Number of arguments
    							, vtOptional
    							, vtOptional//UseISO19005_1
                                , vtOptional//BitmapMissingFonts
    							, vtOptional//DocStructureTags
    							, vtOptional//KeepIRMSettings
    							, vtOptional//IncludeDocProperties
    							, vtOptional//SlideShowName
    							, vtOptional//RangeType
    							, vtOptional//PrintRange
    							, vtOptional//PrintHiddenSlides
    							, vtOptional//OutputType
    							, vtOptional//HandoutOrder
    							, vtOptional//FrameSlide
                                , vtOptional//Intent
    							, varFileType
    							, varOutputFileName
                                );
    
    
    



    karthikeyan

    Monday, April 4, 2016 6:51 AM

All replies

  • Hi Karthikeyan,

    Based on the code and error message, I assume your issue is related with PrintRange parameter. I suggest you set one value for it. You could refer the link below for more information.

    # PowerPoint 2007 SP2, ExportAsFixedFormat in PowerShell?
    http://stackoverflow.com/questions/893675/powerpoint-2007-sp2-exportasfixedformat-in-powershell

    Best Regards,

    Edward

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 5, 2016 2:20 AM
  • Hi Edward,

    You have been given the suggestion in earlier binding, not for late binding. Please try this implementation in late binding.

    Thanks


    karthikeyan

    Tuesday, April 5, 2016 7:26 AM
  • Hi karthikeyan,

    I suggest you set one value for PrintRange parameter. Do you think this is earlier binding?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 5, 2016 9:29 AM
  • Hi Edward,

    Yes, That implementation is earlier binding.  In earlier binding everything is working fine and the exception caught in late binding.  And one more thing, that exception has been raised due to the parameter "PpFixedFormatType" in  ExportAsFixedFormat method and not in PrintRange parameter . Please don't consider the PrintRange parameter because that parameter is optional.

    Thanks


    karthikeyan


    Tuesday, April 5, 2016 11:18 AM
  • Hi Karthik,

    To be honesty, I am not familiar with C++. I just suggest you provide value for PrintRange, I am not sure why you think my way is earlier binding. Anyway, you think that exception has been raised due to the parameter "PpFixedFormatType" in  ExportAsFixedFormat method and not in PrintRange parameter.

    Could you share us a simple project to reproduce your issue at our side?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, April 6, 2016 6:52 AM
  • Hi Edward,

    Sure. below I have given the sample code.

    Thanks

    void PowerPointAutomation()
    {
    	CLSID clsPowerPoint;
    	
    	IOleObject *oleObject;
    
    	HRESULT m_hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    	
    	CLSIDFromProgID(L"POWERPOINT.APPLICATION",&clsPowerPoint);
    		
    	LPOLESTR lpCLSID = (LPOLESTR)CoTaskMemAlloc(128);
    	StringFromCLSID(clsPowerPoint,&lpCLSID);
    	DWORD dwConnection = 0;
    	CComPtr<IDispatch> pdispPowerPointApp = NULL;
    	CComPtr<IDispatch> pdispPresentations = NULL;
    	CComPtr<IDispatch> pdispPresentation = NULL;
    	IUnknown *m_pPPApp = NULL;
    	
    	m_hr = CoCreateInstance(clsPowerPoint, NULL, CLSCTX_ALL, IID_IUnknown, (void**)&m_pPPApp);
    	
    	m_hr = m_pPPApp->QueryInterface(IID_IOleObject, (void **)&oleObject);
    	OleRun(oleObject);
    	
    	oleObject->QueryInterface(IID_IDispatch,(void**)&pdispPowerPointApp);
    	
    	VARIANT vtValue;
    	VariantInit(&vtValue);
    	vtValue.vt = VT_BOOL;
    	vtValue.boolVal = VARIANT_TRUE;
    
    	m_hr =InvokeMember(DISPATCH_PROPERTYPUT, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							NULL,
    							pdispPowerPointApp, 
    							L"Visible", 
    							1
    							,vtValue);
    
    	VARIANT varDispatch;
    	VariantInit(&varDispatch);
    
    	HRESULT hr=InvokeMember(DISPATCH_PROPERTYGET, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&varDispatch,
    							pdispPowerPointApp, 
    							L"Presentations", 
    							0);
    
    	if(varDispatch.vt == VT_ERROR)
    		return;
    	
    	pdispPresentations = varDispatch.pdispVal;
    	VariantClear(&varDispatch);
    	VariantInit(&varDispatch);
    
    	VARIANT vtOptional, vtFileName ,varFileType,varOutputFileName, varOutputType, varHandoutOrder, varPrintHiddenSlides, varPrintComments, varFrameSlide;
    
    	vtOptional.vt = VT_ERROR;
    	vtOptional.scode = DISP_E_PARAMNOTFOUND;
    
    	VariantInit(&vtFileName);
    	vtFileName.vt = VT_BSTR;
    	vtFileName.bstrVal = SysAllocString(L"D:\\Sample1.ppt");
    	hr=InvokeMember(DISPATCH_METHOD, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&varDispatch,
    							pdispPresentations, 
    							L"Open", 
    							4
    							,vtOptional
    							,vtOptional
    							,vtOptional
    							,vtFileName);
    	
    		pdispPresentation = varDispatch.pdispVal;
    		
    		VARIANT result;
    		VariantInit(&result);
    
    		VariantInit(&varFileType);
    		varFileType.vt = VT_I4;
    		varFileType.lVal = 2;
    		COleVariant varFileType1(varFileType);
    		
    		VariantInit(&varOutputFileName);
    		varOutputFileName.vt = VT_BSTR;
    		varOutputFileName.bstrVal = SysAllocString(L"D:\\Output.pdf");
    
    		VariantInit(&varOutputType);
    		varOutputType.vt = VT_I4;
    		varOutputType.lVal = 32;
    
    		VariantInit(&varHandoutOrder);
    		varHandoutOrder.vt = VT_I4;
    		varHandoutOrder.lVal = 0;
    
    		VariantInit(&varPrintHiddenSlides);
    		varPrintHiddenSlides.vt = VT_BOOL;
    		varPrintHiddenSlides.boolVal = 0;
    
    		VariantInit(&varPrintComments);
    		varPrintComments.vt = VT_BOOL;
    		varPrintComments.boolVal = 0;
    
    		VariantInit(&varFrameSlide);
    		varFrameSlide.vt = VT_BOOL;
    		varFrameSlide.boolVal = 0;
    
    		VARIANT varDisp;
    		VariantInit(&varDisp);
    		varDisp.vt = VT_DISPATCH;
    			
           
    
    		hr=InvokeMember(DISPATCH_METHOD, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&result, 
    							pdispPresentation, 
    							L"ExportAsFixedFormat", 
    							16 // Number of arguments
    							, vtOptional
    							, vtOptional//UseISO19005_1
                                , vtOptional//BitmapMissingFonts
    							, vtOptional//DocStructureTags
    							, vtOptional//KeepIRMSettings
    							, vtOptional//IncludeDocProperties
    							, vtOptional//SlideShowName
    							, vtOptional//RangeType
    							, vtOptional//PrintRange
    							, vtOptional//PrintHiddenSlides
    							, vtOptional//OutputType
    							, vtOptional//HandoutOrder
    							, vtOptional//FrameSlide
                                , vtOptional//Intent
    							, varFileType//FileFormatType
    							, varOutputFileName //FileName
                                );
    		if(hr != S_OK)
    		{
    			
    		}
    		hr = InvokeMember(DISPATCH_METHOD, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&result, 
    							pdispPresentation, 
    							L"Close",NULL);
    
    		oleObject->Close(OLECLOSE_NOSAVE);
    
    		hr = InvokeMember(DISPATCH_METHOD, // can be DISPATCH_METHOD, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET
    							&result, 
    							pdispPresentation, 
    							L"Quit",NULL);
    
    		CoUninitialize();
    }


    karthikeyan

    Thursday, April 7, 2016 6:56 AM
  • Hi karthikeyan,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best Regards,

    Edward

     

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 8, 2016 1:03 AM