unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj,
ActiveX, WMPLib_TLB;
type
TfrmMain =
class(TForm)
init2: TButton;
procedure init2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
frmMain: TfrmMain;
implementation
var
WMP : IWMPPlayer4Disp;
RES : IWMPPlayer4;
const
IID_IClassFactory: TGUID = (
D1:$00000001;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));
{$R *.dfm}
procedure TfrmMain.init2Click(Sender: TObject);
var hr : HRESULT;
mpclassid : TGUID;
//CLSID
cf : IClassFactory;
iid : TIID;
begin
hr := CLSIDFromProgID('
WMPlayer.OCX.7', mpclassid);
if Failed(hr)
then begin
showmessage('
Failed getting classid for Windows Media Player');
Exit;
end;
hr := CoGetClassObject(mpclassid, CLSCTX_ALL,
nil, IID_IClassFactory, cf);
if Failed(hr)
then begin
showmessage('
Fehler');
Exit;
end;
hr := cf.CreateInstance(
nil, IID_IWMPControls, CTL);
if Failed(hr)
then begin
showmessage('
Failed Instantiate Controls');
Exit;
end;
hr := CoCreateInstance(mpclassid,
nil, CLSCTX_INPROC_SERVER, IID_IWMPPlayer4, res);
if Failed(hr)
then begin
showmessage('
Failed instantiating Windows Media Player control!');
Exit;
end;
WMP := RES
as IWMPPlayer4Disp;
CTL.play;
//nichts tut sich
//Das würde funktionieren: (mit laufender Instanz)
//WMP.openPlayer('C:\Test.mp3');
end;
initialization
CoInitialize(
nil);
end.