interface cast failure

Hi

I'm trying to use the WMPLib.IWMPCdRomRip interface but I keep gettng an error.

I'm using Windows XP SP2 Danish, Visual Basic .net 2003 and .net framwork 1.1

Based on this (from Windows Media Player 11 SDK):

"Get anIWMPCdromRip interface by casting theIWMPCdrom interface of the CD that you wish to rip."

I'm doing this(short version)

Public iCdRipAs WMPLib.IWMPCdromRip

Public iCdRomAs WMPLib.IWMPCdrom

PublicWithEvents PlayerAs WMPLib.WindowsMediaPlayer

iCdRom = Player.cdromCollection.Item(0)

iCdRom = iCDRip 'THIS LINE FAILS. It says (in danish) that it is an invalid pointer.

What am doing wrong? Hope somebody in here can help.

Lars

[1315 byte] By [LarsJensen] at [2007-12-25]
# 1

I don't really know anything about using mediaplayer like that, but, the instruction you posted says to cast IWMPcdrom to IWMPcdromrip so try using a casting statement:

Public iCdRip As WMPLib.IWMPCdromRip

Public iCdRom As WMPLib.IWMPCdrom

Public WithEvents Player As WMPLib.WindowsMediaPlayer

iCdRom = Player.cdromCollection.Item(0)

iCdRip = CType(iCdRom, IWMPCdromRip)

rkimble at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

When doing this: (where "Player" is WMPLib.WindowsMediaPlayer)

Dim iCdRom As WMPLib.IWMPCdrom = Player.cdromCollection.Item(0)

Dim oCdRipper As WMPLib.IWMPCdromRip = iCdRom

ocdripper.startRip()

It's actually the last line that's causing the "invalid pointer" but both line 1 and 2 is succesful.(The error message is a direct translation from danish so I don't know what it really says in english.)

Anybody got any idea why?

LarsJensen at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Okay I found the solution.

I for some reason have to retrieve the playlist from the cdrom interface before calling the startRip method.

These lines will work and rip a cd according to your settings in Wiondows Media Player (remember to delete the "templist" when done):

Dim iCdRom As WMPLib.IWMPCdrom = Player.cdromCollection.Item(0)

Dim objTempPlaylist As WMPLib.IWMPPlaylist = Player.newPlaylist("templist", "")

Dim iCdRipper As WMPLib.IWMPCdromRip = iCdRom

objTempPlaylist = iCdRom.Playlist

iCdRipper.startRip()

LarsJensen at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...