703
社区成员




//这是我要调用的函数,这个函数的最后一个参数,就是我出问题的地方,它需要下面那个接口的指针
HRESULT __fastcall EncodeFile(BSTR FileName/*[in]*/, BSTR
OutputFileName/*[in]*/,
BSTR Parameters/*[in]*/,
unsigned ResampleSampleRate/*[in]*/,
unsigned Channels/*[in]*/,
double StartPosition/*[in]*/,
double Length/*[in]*/,
double Normalize/*[in]*/,
Bassencoder_tlb::IProgress* ProgressCallback/*[in]*/);
//这是接口
// *********************************************************************//
// Interface: IProgress
// Flags: (4352) OleAutomation Dispatchable
// GUID: {C23CF58D-3121-45D2-A0DB-B19F98350D52}
// *********************************************************************//
interface IProgress : public IDispatch
{
public:
HRESULT STDMETHODCALLTYPE ProgressCallback(double Progress/*[in]*/); // [201]
};
“class TFormMain : public TForm”
“class TFormMain : public TForm ,public IProgress”
HRESULT STDMETHODCALLTYPE TFormMain::ProgressCallback(double Progress)
{
pb1->Position=(int)(Progress);
return S_OK;
}
EncodeFile(.............(IProgress*)this);
HRESULT STDMETHODCALLTYPE IProgress::ProgressCallback(double Progress)
{
//pb1->Position=(int)(Progress);
return S_OK;
}
EncodeFile(.............(IProgress*)this);
EncodeFile(.............this);
class TFormMain : public TForm,public IProgress
{
__published: // IDE-managed Components
TButton *btn1;
TProgressBar *pb1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall btn1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
HRESULT _fastcall ProgressCallback(double Progress);
public: // User declarations
__fastcall TFormMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
源文件:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FormMainUnit.h"
//----------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
HRESULT _fastcall TFormMain::ProgressCallback(double Progress)
{
//pb1->Position=(int)(Progress);
return S_OK;
}
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TFormMain::btn1Click(TObject *Sender)
{
IBASSEncodeFile BASSEncodeFileMP3;
HResult Error;
//* Acquire the class
BASSEncodeFileMP3 = (IBASSEncodeFile)CreateComObject(CLASS_TBASSEncodeFileMP3);
//* Generate MP3, CBR 320 kbps, 44100 Hz, 2 channels (stereo)
Error = BASSEncodeFileMP3.EncodeFile(EditInputFileName->Text, EditOutputFileName->Text, "-b 320", 44100, 2, 0, 0, 0, this);
}
CB中的代码就这些,Delphi可以运行的例子,全部代码就在上面4楼,现在的问题就是,CB运行会报错:“Pure virtual function called”。。。。。
搜索了一些相关资料,没有得到答案
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BASSEncoder_TLB, Vcl.ComCtrls;
type
TForm1 = class(TForm, IProgress)
Button2: TButton;
GroupBox1: TGroupBox;
Button3: TButton;
Label1: TLabel;
EditInputFileName: TEdit;
Button4: TButton;
EditOutputFileName: TEdit;
Label2: TLabel;
Button5: TButton;
Label3: TLabel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ProgressBar1: TProgressBar;
Button1: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Label4: TLabel;
EditCommandLine: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
//procedure Button9Click(Sender: TObject);
private
{ Private declarations }
function ProgressCallback(Progress: Double): HResult; stdcall;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Uses
//BASSEncoderLibrary,
ComObj;
//* Example to call the DLL class directly without COM (requires BASSEncoderLibrary.pas in the Uses list):
{
procedure TForm1.Button9Click(Sender: TObject);
var
BASSEncodeFileMP3: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileMP3 := BASSEncoderGetFileMP3;
//* Generate MP3, CBR 320 kbps, 44100 Hz, 2 channels (stereo)
Error := BASSEncodeFileMP3.EncodeFile(EditInputFileName.Text, EditOutputFileName.Text, '-b 320', 44100, 2, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
}
procedure TForm1.Button7Click(Sender: TObject);
var
BASSEncodeFileMP3: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileMP3 := CreateComObject(CLASS_TBASSEncodeFileMP3) as IBASSEncodeFile;
//* Generate MP3, CBR 320 kbps, 44100 Hz, 2 channels (stereo)
Error := BASSEncodeFileMP3.EncodeFile(EditInputFileName.Text, EditOutputFileName.Text, '-b 320', 44100, 2, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
BASSEncodeFileOpus: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileOpus := CreateComObject(CLASS_TBASSEncodeFileOpus) as IBASSEncodeFile;
//* Generate Opus, 320 kbps
Error := BASSEncodeFileOpus.EncodeFile(EditInputFileName.Text, EditOutputFileName.Text, '--bitrate 320', 0, 0, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BASSEncodeFileFLAC: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileFLAC := CreateComObject(CLASS_TBASSEncodeFileFLAC) as IBASSEncodeFile;
//* Generate FLAC
Error := BASSEncodeFileFLAC.EncodeFile(EditInputFileName.Text, EditOutputFileName.Text, '--best', 0, 0, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
BASSEncodeFileOggVorbis: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileOggVorbis := CreateComObject(CLASS_TBASSEncodeFileVorbis) as IBASSEncodeFile;
//* Generate Ogg Vorbis, 320 kbps
Error := BASSEncodeFileOggVorbis.EncodeFile(EditInputFileName.Text, EditOutputFileName.Text, '--bitrate 320', 0, 0, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
BASSEncodeFileCommandLine: IBASSEncodeFile;
Error: HResult;
begin
//* Acquire the class
BASSEncodeFileCommandLine := CreateComObject(CLASS_TBASSEncodeFileCommandLine) as IBASSEncodeFile;
//* Encode a MusePack file (replace '{outputfilename}' with specified output file name and convert extension to .mpc)
Error := BASSEncodeFileCommandLine.EncodeFile(EditInputFileName.Text, ChangeFileExt(EditOutputFileName.Text, '.mpc'), StringReplace(EditCommandLine.Text, '{outputfilename}', '"' + ChangeFileExt(EditOutputFileName.Text, '.mpc') + '"', [rfReplaceAll]), 0, 0, 0, 0, 0, Self);
if Error <> 0 then begin
Showmessage('Error: ' + IntToStr(Error));
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
OpenDialog1.FileName := EditInputFileName.Text;
if OpenDialog1.Execute then begin
EditInputFileName.Text := OpenDialog1.FileName;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
SaveDialog1.FileName := EditOutputFileName.Text;
if SaveDialog1.Execute then begin
EditOutputFileName.Text := SaveDialog1.FileName;
end;
end;
function TForm1.ProgressCallback(Progress: Double): HResult; stdcall;
begin
ProgressBar1.Position := Round(Progress);
Result := S_OK;
end;
end.
这是Delphi例子的所有代码,就这些,我觉得我C++ Builder里面的代码和这个应该没有什么出入,但就是运行不了。。