MSDN LibraryのIMPAIv2の"Using IMAPI"中にあるサンプルコード
http://msdn.microsoft.com/en-us/library/aa364817(VS.85).aspx
を、Visual Basic 2008に組み込んで実行すると、
dataWriter.recorder = Recorder
の行で、「COMExceptionはハンドルされませんでした。」
というエラーが出て止まってしまいます。
OSはXP Professionai Edition SP3と、
Vista Bussines Editionで実行しましたが、
全く同じ結果でした。
このサンプルコードは、Visual Basic 2008では
使用できないのでしょうか?
------------------------------------------------------------------
サンプルコード(Burning a Disc Image)
' This script burns data files to disc in a single session
' using files from a single directory tree.
' Copyright (C) Microsoft Corp. 2006
Option Explicit
' *** CD/DVD disc file system types
Const FsiFileSystemISO9660 = 1
Const FsiFileSystemJoliet = 2
Const FsiFileSystemUDF102 = 4
WScript.Quit(Main)
Function Main
Dim Index ' Index to recording drive.
Dim Recorder ' Recorder object
Dim Path ' Directory of files to burn
Dim Stream ' Data stream for burning device
Index = 1 ' Second drive on the system
Path = "g:\BurnDir" ' Files to transfer to disc
' Create a DiscMaster2 object to connect to optical drives.
Dim g_DiscMaster
Set g_DiscMaster = WScript.CreateObject("IMAPI2.MsftDiscMaster2")
' Create a DiscRecorder object for the specified burning device.
Dim uniqueId
set recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
uniqueId = g_DiscMaster.Item(index)
recorder.InitializeDiscRecorder( uniqueId )
' Create an image stream for a specified directory.
Dim FSI ' Disc file system
Dim Dir ' Root directory of the disc file system
Dim dataWriter
' Create a new file system image and retrieve root directory
Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")
Set Dir = FSI.Root
'Create the new disc format and set the recorder
Set dataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
dataWriter.recorder = Recorder
dataWriter.ClientName = "IMAPIv2 TEST"
FSI.ChooseImageDefaults(recorder)
' Add the directory and its contents to the file system
Dir.AddTree Path, false
' Create an image from the file system
Dim result
Set result = FSI.CreateResultImage()
Stream = result.ImageStream
' Write stream to disc using the specified recorder.
WScript.Echo "Writing content to disc..."
dataWriter.write(Stream)
WScript.Echo "----- Finished writing content -----"
Main = 0
End Function
------------------------------------------------------------------
そのサンプルは、VBScriptなので・・・
過去ログ!
http://madia.world.coocan.jp/cgi-bin/VBBBS2/wwwlng.cgi?print+200901/09010038.txt
参考まで・・・
以上。
オショウ様
レスありがとうございます。
VBSCriptなのは分かっておりますが、
そのVBScriptは、VB2008のコードに書き直して
使用することはできないのでしょうか?
また、過去ログには、VBのコードでのサンプルが
記述された以下のようなページもありますが、
http://social.msdn.microsoft.com/Forums/en-US/windowsopticalplatform/thread/f73e5d11-f7e7-4b7b-9e8a-d2f2237f2ee2/
(VistaでCDを焼くVBのサンプルコード)
どうしても、
Dim DiscMaster As New MsftDiscMaster2
のようなオブジェクトの宣言で、
「型 MsftDiscMaster2が宣言されていません。」
と出てしまいます。
VBでIMAPI2を使用するには、
imapi.dllの参照設定等をする必要があるのでしょうか?
それも魔界の仮面弁士殿があげられているURLの5件目
に書かれてますが・・・
要は参照設定が抜けている為、IMAPI2の機能が呼べないの
です。
参照設定でCOMタブの方の
Microsoft IMAPI2 Base Functionality
Microsoft IMAPI2 File System Image Creator
を選択して下さい。
以上。
オショウ様
参照設定を付け加えたところ、
無事動作し、CDへの書き込みが出来ました。
ありがとうございました。
また、今後同じ問題でつまづく人の為に、
ひとつ付け加えると、
のサンプルコードはIMAPIの定義の部分で、
やはりエラーになってしまうので、一部書き換えが必要です。
例
Dim DiscMaster As New MsftDiscMaster2
↓
Dim DiscMaster As New IMAPI2.MsftDiscMaster2
この書き換えで、問題なく書込みまで
動作確認が出来ました。
ツイート | ![]() |