Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem to open ppt file using automation.

Problem to open ppt file using automation.

Scheduled Pinned Locked Moved C / C++ / MFC
helpioscomtestingtools
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    hi help me to open ppt file using automation. this working well for excel and word files but ppt files are not open from this. can u please correct me where I m wrong

    //for ppt files

    ifstream in_fp;
    DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
    VARIANT vResult; // used to hold variant results
    OLECHAR FAR* szFunction;
    IDispatch* pDispApp;
    IDispatch* pDispXlBooks;
    DISPID dispid_Books; //Documents property of application object
    DISPID dispid_Quit;
    BSTR bstrFileName = ::SysAllocString(OLESTR("filename"));
    BSTR bstrPassWord = ::SysAllocString(OLESTR("pass"));

    CString error\_str=\_T("");
    in\_fp.open(file\_name, ios::in);
    if (!in\_fp || file\_name.GetLength() > MAX\_PATH)
    {
    	error\_str.Format(\_T("error loading %s\\n"), file\_name);
    	AfxMessageBox(error\_str);
    	return ;
    }
    
    string ss = string(CT2CA(file\_name));
    
    const char \*szFileName = ss.c\_str();
    
    wchar\_t wszFileName\[MAX\_PATH+1\];
    
    //convert file name to bstr for use with COM
    MultiByteToWideChar(CP\_ACP, 0, szFileName, strlen(szFileName)+1,
    		wszFileName, sizeof(wszFileName)/sizeof(wszFileName\[0\]));
    
    bstrFileName = ::SysAllocString(wszFileName);
    
    // COM work starts here
    
    //Initialize COM
    ::CoInitialize(NULL);
    
    
    //get the CLSID for the Excel Application Object
    CLSID clsid;
    

    //for word files
    //use "Word.Application"

    //and for excel files
    //use "Excel.Application"

    CLSIDFromProgID(L"Powerpoint.Application", &clsid);
    
    //get a pointer to the Objects IUnknown interface and Create
    //an instance of the Excel Application.
    
    IUnknown\* pUnk;
    HRESULT hr = ::CoCreateInstance( clsid, NULL,
    		CLSCTX\_SERVER, IID\_IUnknown, (void\*\*) &pUnk);
    
    
    
    hr = pUnk->QueryInterface(IID\_IDispatch, (void\*\*)&pDispApp);
    

    //for word files
    //use "Documents"

    //and for excel files
    //use "Workbooks"

    szFunction = OLESTR("Presentations");
    hr = pDispApp->GetIDsOfNames (IID\_NULL, &szFunction, 1,
    		LOCALE\_USER\_DEFAULT, &dispid\_Books);
    
    hr = pDispApp->Invoke (dispid\_Books, IID\_NULL,
    		LOCALE\_USER\_DEFAULT, DISPATCH\_PROPERTYGET,
    		&dpNoArgs, &vResult, NULL, NULL);
    
    pDispXlBooks = vResult.pdispVal;
    
    //DISPPARAMS for Open method
    
    DISPID dispid\_Open;
    VARIANT vArgsOpen\[5\];
    DISPPARAMS dpOpen;
    dpOpen.cArgs = 5;
    dpOpen.cNamedArgs = 0;
    dpOpen.rgvarg = vArgsOpen;
    
    wchar\_t wszPassWord\[MAX\_PATH\];
    
    
    ss = string(CT2CA(Password));
    
    const char \*pwd\_entry = ss.c\_str();
    
    //again convert to bstr
    MultiByteToWideChar(CP\_ACP, 0, pwd\_entry, -1,
    		ws
    
    J 1 Reply Last reply
    0
    • L Le rner

      hi help me to open ppt file using automation. this working well for excel and word files but ppt files are not open from this. can u please correct me where I m wrong

      //for ppt files

      ifstream in_fp;
      DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
      VARIANT vResult; // used to hold variant results
      OLECHAR FAR* szFunction;
      IDispatch* pDispApp;
      IDispatch* pDispXlBooks;
      DISPID dispid_Books; //Documents property of application object
      DISPID dispid_Quit;
      BSTR bstrFileName = ::SysAllocString(OLESTR("filename"));
      BSTR bstrPassWord = ::SysAllocString(OLESTR("pass"));

      CString error\_str=\_T("");
      in\_fp.open(file\_name, ios::in);
      if (!in\_fp || file\_name.GetLength() > MAX\_PATH)
      {
      	error\_str.Format(\_T("error loading %s\\n"), file\_name);
      	AfxMessageBox(error\_str);
      	return ;
      }
      
      string ss = string(CT2CA(file\_name));
      
      const char \*szFileName = ss.c\_str();
      
      wchar\_t wszFileName\[MAX\_PATH+1\];
      
      //convert file name to bstr for use with COM
      MultiByteToWideChar(CP\_ACP, 0, szFileName, strlen(szFileName)+1,
      		wszFileName, sizeof(wszFileName)/sizeof(wszFileName\[0\]));
      
      bstrFileName = ::SysAllocString(wszFileName);
      
      // COM work starts here
      
      //Initialize COM
      ::CoInitialize(NULL);
      
      
      //get the CLSID for the Excel Application Object
      CLSID clsid;
      

      //for word files
      //use "Word.Application"

      //and for excel files
      //use "Excel.Application"

      CLSIDFromProgID(L"Powerpoint.Application", &clsid);
      
      //get a pointer to the Objects IUnknown interface and Create
      //an instance of the Excel Application.
      
      IUnknown\* pUnk;
      HRESULT hr = ::CoCreateInstance( clsid, NULL,
      		CLSCTX\_SERVER, IID\_IUnknown, (void\*\*) &pUnk);
      
      
      
      hr = pUnk->QueryInterface(IID\_IDispatch, (void\*\*)&pDispApp);
      

      //for word files
      //use "Documents"

      //and for excel files
      //use "Workbooks"

      szFunction = OLESTR("Presentations");
      hr = pDispApp->GetIDsOfNames (IID\_NULL, &szFunction, 1,
      		LOCALE\_USER\_DEFAULT, &dispid\_Books);
      
      hr = pDispApp->Invoke (dispid\_Books, IID\_NULL,
      		LOCALE\_USER\_DEFAULT, DISPATCH\_PROPERTYGET,
      		&dpNoArgs, &vResult, NULL, NULL);
      
      pDispXlBooks = vResult.pdispVal;
      
      //DISPPARAMS for Open method
      
      DISPID dispid\_Open;
      VARIANT vArgsOpen\[5\];
      DISPPARAMS dpOpen;
      dpOpen.cArgs = 5;
      dpOpen.cNamedArgs = 0;
      dpOpen.rgvarg = vArgsOpen;
      
      wchar\_t wszPassWord\[MAX\_PATH\];
      
      
      ss = string(CT2CA(Password));
      
      const char \*pwd\_entry = ss.c\_str();
      
      //again convert to bstr
      MultiByteToWideChar(CP\_ACP, 0, pwd\_entry, -1,
      		ws
      
      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You should check the HRESULT return value of each function call and break execution upon failure. Then you know which call fails first and you can check the passed parameters.

      L 1 Reply Last reply
      0
      • J Jochen Arndt

        You should check the HRESULT return value of each function call and break execution upon failure. Then you know which call fails first and you can check the passed parameters.

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        its fail when I m trying to "open" and same this working fine for word and excel files.

        J 1 Reply Last reply
        0
        • L Le rner

          its fail when I m trying to "open" and same this working fine for word and excel files.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          I have not use OLE automation with PowerPoint so far. But the error

          Quote:

          "invalid number of parameters"

          indicates that the PowerPoint Open() method has other parameters than Excel or Word. See https://support.microsoft.com/kb/222758/en-us[^] for the Presentations.Open() method.

          L 1 Reply Last reply
          0
          • J Jochen Arndt

            I have not use OLE automation with PowerPoint so far. But the error

            Quote:

            "invalid number of parameters"

            indicates that the PowerPoint Open() method has other parameters than Excel or Word. See https://support.microsoft.com/kb/222758/en-us[^] for the Presentations.Open() method.

            L Offline
            L Offline
            Le rner
            wrote on last edited by
            #5

            please help me or ole automation with powerpoint...

            L 1 Reply Last reply
            0
            • L Le rner

              please help me or ole automation with powerpoint...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              See http://support.microsoft.com/kb/222960[^].

              Veni, vidi, abiit domum

              L 1 Reply Last reply
              0
              • L Lost User

                See http://support.microsoft.com/kb/222960[^].

                Veni, vidi, abiit domum

                L Offline
                L Offline
                Le rner
                wrote on last edited by
                #7

                so there is no option to open password protected PPT files in automation?

                L 1 Reply Last reply
                0
                • L Le rner

                  so there is no option to open password protected PPT files in automation?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Sorry, I don't know. You will need to check the documentation details.

                  L 1 Reply Last reply
                  0
                  • L Lost User

                    Sorry, I don't know. You will need to check the documentation details.

                    L Offline
                    L Offline
                    Le rner
                    wrote on last edited by
                    #9

                    ok sir.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups