Convert vbscript into vb6 code for imapi controls

eneate
eneate used Ask the Experts™
on
Hi

I am working through another section of vbscript to convert to vb6 i have attached the section of vb script

the first part is fine

Private DiscMaster As New MsftDiscMaster2
 Private DiscRecorder As New MsftDiscRecorder2

then in the sub

Dim datawriter As MsftDiscFormat2Data
Set datawriter = New MsftDiscFormat2Data
                 
    ' Create a DiscRecorder object for the specified burning device.
   
      DiscRecorder.InitializeDiscRecorder DiscMaster.Item(0)

 If datawriter.IsRecorderSupported(DiscRecorder) <> True Then
        MsgBox "The current CD/DVD writer on your system does not support writing to disc.", vbSystemModal + vbOKOnly + vbCritical
        Exit Function
    End If

If datawriter.IsCurrentMediaSupported(DiscRecorder) <> True Then
        MsgBox "Current optical media IS NOT supported.", vbSystemModal + vbOKOnly
        Exit Function
    End If

Debug.Print "ClientName = " & datawriter.ClientName

but although datawriter is recognied it is not passing any data and the debug code for clientname is empty.

everything i have tried with currentmedia status fails

any help would be appreciated, sorry but this is the first time i have used imapi or vbscript... ;-)
Dim Index                ' Index to recording drive.
    Dim recorder             ' Recorder object
    Dim Stream               ' Data stream for burning device
    
    Index = 1                ' Second drive on the system

    ' Create a DiscMaster2 object to connect to CD/DVD 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 )

    ' Define the new disc format and set the recorder
    Dim dataWriter
    Set dataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    dataWriter.recorder = recorder

    Dim boolResult
    boolResult = dataWriter.IsRecorderSupported(recorder)
    If boolResult = True then
        WScript.Echo "--- Current recorder IS supported. ---"
    else
        WScript.Echo "Current recorder IS NOT supported."
    end if

    boolResult = dataWriter.IsCurrentMediaSupported(recorder)
    If boolResult = True then
        WScript.Echo "--- Current media IS supported. ---"
    else
        WScript.Echo "Current media IS NOT supported."
    end if

    WScript.Echo "ClientName = " & dataWriter.ClientName

    ' Check a few CurrentMediaStatus possibilities. Each status
    ' is associated with a bit and some combinations are legal.
    Dim curMediaStatus
    curMediaStatus = dataWriter.CurrentMediaStatus
    WScript.Echo "Checking Current Media Status"

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
Make sure you visit here for the error codes.  If you .CurrentMediaStatus and there is no media in the recorder it will throw E_IMAPI_RECORDER_MEDIA_NO_MEDIA (0xC0AA0202).  There is more errors that could be thrown also for this so you have visit document page for them to know for sure.
The .ClientName is what you place into it such as your Application Name for example.
IMAPI Return Values
http://msdn.microsoft.com/en-us/library/cc835244(VS.85).aspx
 

Sub DumpInfo2()
  
  
  Dim DiscMaster        As MsftDiscMaster2
  Dim DiscRecorder      As MsftDiscRecorder2
  Dim DiscWriter        As MsftDiscFormat2Data
  
  Set DiscMaster = New MsftDiscMaster2
  Set DiscRecorder = New MsftDiscRecorder2
  Set DiscWriter = New MsftDiscFormat2Data
  
  '   Select first recorder device on system.
  DiscRecorder.InitializeDiscRecorder DiscMaster.Item(0)
  
  '   Set the DiscRecorder
  DiscWriter.Recorder = DiscRecorder
  '   You set the client name. This is your application name typically.
  DiscWriter.ClientName = "My Application"
  
  Dim bSupported      As Boolean
  bSupported = DiscWriter.IsRecorderSupported(DiscRecorder)
  If bSupported = True Then
    Debug.Print "--- Current recorder IS supported. ---"
  Else
    Debug.Print "Current recorder IS NOT supported."
  End If
  
  bSupported = DiscWriter.IsCurrentMediaSupported(DiscRecorder)
  If bSupported = True Then
    Debug.Print "--- Current media IS supported. ---"
  Else
    Debug.Print "Current media IS NOT supported."
  End If
  
  Debug.Print "ClientName = " & DiscWriter.ClientName
  
  Dim curMediaStatus As IMAPI_FORMAT2_DATA_MEDIA_STATE
  curMediaStatus = DiscWriter.CurrentMediaStatus
  Debug.Print curMediaStatus

End Sub

Open in new window

Author

Commented:
Thanks, very much i really appreciate your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial