- - PR -
PowerPointのプロセスが終了しません
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2004-11-15 14:41
Todoさんご返答ありがとうございました。
ご紹介していただいたページも参考にさせていただいたのですが、 特にこれが足りないといったところもありませんでした。 以下にコードを記します。 '------------------------------------------------------------------------------ 'PowerPoint起動 '引数:sTemplate(起動ファイルパス) '--------------------------------------------------------------------------- Public Sub StartPowerPoint(ByVal sTemplate As String) Dim oApp As PowerPoint.Application Dim oPres As PowerPoint.Presentations Dim oPre As PowerPoint.Presentation Dim PwrPntWindow As PowerPoint.PpWindowState '変数の開放 PwrPntWindow = Nothing oPres = Nothing oPre = Nothing oApp = Nothing oApp = New PowerPoint.Application 'Powerpoint を起動し、ウィンドウを最小化して表示します。 oApp.Visible = True oApp.WindowState = PwrPntWindow.ppWindowMaximized '指定したテンプレートを基に新しいプレゼンテーションを作成します。 oPres = oApp.Presentations oPre = oPres.Open(sTemplate, , , True) 'COMオブジェクトの開放 System.Runtime.InteropServices.Marshal.ReleaseComObject(PwrPntWindow) System.Runtime.InteropServices.Marshal.ReleaseComObject(oPres) System.Runtime.InteropServices.Marshal.ReleaseComObject(oPre) System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp) '使用した変数の開放 PwrPntWindow = Nothing oPres = Nothing oPre = Nothing oApp = Nothing System.GC.Collect() End Sub '------------------------------------------------------------------------------- 'スライドショーの実行 '引数なし '--------------------------------------------------------------------------- Public Sub SlideShow() 'スライドショーを実行します。 Dim oApp As PowerPoint.Application Dim oSlidesActPre As PowerPoint.Presentation Dim oSettings As PowerPoint.SlideShowSettings Dim oAppSlideWindows As PowerPoint.SlideShowWindows '変数の開放 oAppSlideWindows = Nothing oSettings = Nothing oSlidesActPre = Nothing oApp = Nothing oApp = New PowerPoint.Application oSlidesActPre = oApp.ActivePresentation oSettings = oSlidesActPre.SlideShowSettings oAppSlideWindows = oApp.SlideShowWindows 'スライド ショーを実行し、ユーザーがPowerPointを閉じるまで待機 oSettings.Run() Dim I As Integer = 1 Do While I < 10 If Not oApp.Visible = True Then Exit Do End If Loop 'COMオブジェクトの開放 System.Runtime.InteropServices.Marshal.ReleaseComObject(oAppSlideWindows) System.Runtime.InteropServices.Marshal.ReleaseComObject(oSettings) System.Runtime.InteropServices.Marshal.ReleaseComObject(oSlidesActPre) System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp) '使用した変数の開放 oAppSlideWindows = Nothing oSettings = Nothing oSlidesActPre = Nothing oApp = Nothing System.GC.Collect() End Sub このコードを記述したクラスをDLLにして、VB.NET側で呼んでいます。 「oSettings.Run()」を実行しただけで、プロセスが残ってしまうので この実行によりRCW(ランタイム呼び出し可能ラッパー)に参照カウントが保持されていると 思われるのですが、使用した変数「oSettings」も開放しています。 どなたかご指摘、これは試したか、などなんでも構いませんので 知恵をお貸しください。 |
|
投稿日時: 2004-11-15 16:18
ご教授していただいたみなさんありがとうございました。
無事プロセスを消すことができました。 コードがまずかったようです。 「oSettings.Run()」で実行すると暗黙的なオブジェクトが生成されてしまうようです。 これを、明示的に Dim oSettingsRun As PowerPoint.SlideShowWindow oSettingsRun = oSettings.Run()として 後は oSettingsRunにかかる全ての参照を開放すればいけました。 実行ロジックにも明示的なオブジェクトを指定すればよいだけでした。 お騒がせして申し訳ありません。 ありがとうございました。 |