3

I'm new to .NET. I want to make a console application that converts a .pptx file into a .wmv.I've managed to do this using powerpoint interop.But i have some problems.First If i build the application and tranfer it to another computer i get an exception Error HRESULT E_FAIL has been returned for COM object(i have powerpoint in both PCs).If i run it on the one that i wrote it i everything works alright.But not for the first time.Meaning that when i start my pc and run it i'll get the same exception and the second time i'll try to run it will run properly.What could be the problem?iguess something with interop and powerpoint but i can't figure it out.

Ok here is the code:

using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using System.Runtime.InteropServices;
using System.IO;
using System;

  namespace Microsoft.Office.Interop.PowerPoint
 {
  class Program
  {

    static void Main(string[] args)
    {

        string fileName = args[0];
        string exportName = args[1];
        string exportPath = args[2];

        Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
        ppApp.Visible = MsoTriState.msoTrue;
        ppApp.WindowState = PpWindowState.ppWindowMinimized;
        Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
        Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(fileName,
                    MsoTriState.msoFalse, MsoTriState.msoFalse,
                    MsoTriState.msoFalse);
        try
        {
            oPres.CreateVideo(exportName);
            oPres.SaveCopyAs(String.Format(exportPath, exportName),
                PowerPoint.PpSaveAsFileType.ppSaveAsWMV,
                MsoTriState.msoCTrue);
        }
        finally
        {
            ppApp.Quit();
        }
    }

}
}
Libathos
  • 3,340
  • 5
  • 36
  • 61
  • This question is impossible to answer without more details, I'm afraid... How do you try to execute PPT? Are the OSes on both machines the same? Etc. – Roy Dictus Nov 15 '12 at 14:33
  • Very probably some COM are not loaded at first and so it crashes by the time you launch it the second time it has loaded so no error – csharpwinphonexaml Aug 21 '15 at 16:16

1 Answers1

0

_Presentation.CreateVideo doesn't create a video out of a powerpoint. It creates a video inside of a powerpoint. That's what the documentation says, anyway.

Try _Presentation.SaveAs and then use PpSaveAsFileType.ppSaveAsWMV for the file type.