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.IWMPCdromRipPublic iCdRomAs WMPLib.IWMPCdromPublicWithEvents PlayerAs WMPLib.WindowsMediaPlayeriCdRom = 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
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)
When doing this: (where "Player" is WMPLib.WindowsMediaPlayer)
Dim iCdRom As WMPLib.IWMPCdrom = Player.cdromCollection.Item(0) Dim oCdRipper As WMPLib.IWMPCdromRip = iCdRomocdripper.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?
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 = iCdRomobjTempPlaylist = iCdRom.Playlist
iCdRipper.startRip()