[Delphi 7] - Events

Hello.

How can I handle NeroDrive-events with Delphi 7?

Joe09

I was able to get events to work with delphi 7.

Now trying to figure out how to do a Multisession Disk.

mmgrover

I am eager to know this aswell, somehow the NereDrive and NeroDrives events are not exported when using the Import type library :S. Anyways hope someone reply, if someone needs to know how to burn things like audio or whatever, feel free to ask, i just need 2 know how to access those events, the rest is pretty simple.

Michel.

I was able to get events to work with delphi 7.

And how did you get them working ?

I tried to import the NERO - TLB and as everybody I looked for the events of the
INeroDrive object which weren’t there.

So I wrote a little wrapper which functions the following way:

The object you want to receive has to implement my defined INeroDriveEvents
interface.
Then a TNeroDriveEvents object has to be created and the InvokableObject
property has to be set.

I used this wrapper e.g. for querying cd info like this

           drive.CDInfo(NERO_READ_CD_TEXT or NERO_READ_ISRC);

           for j := 0 to 1000 do
           begin
                sleep(10);
                Application.ProcessMessages;
           end;

Please if anybody can use this code report back if there are some
errors!

kind regards
Mike

Code of the wrapper:
unit NeroEventWrapper;

interface

uses
NEROLib_TLB;

type
INeroDriveEvents = interface(IDispatch)
[’{D149A7EF-E0BB-4FDC-8DE6-8D2D441DEC34}’]
procedure OnProgress(var ProgressInPercent: Integer; var Abort: WordBool);
procedure OnAddLogLine(var TextType: NERO_TEXT_TYPE; var Text: WideString);
procedure OnSetPhase(var Text: WideString);
procedure OnDisableAbort(var EnableAbort: WordBool);
procedure OnWriteDAE(var ignore: Integer; var Data: OleVariant);
procedure OnDoneDAE(var Ok: WordBool);
procedure OnDoneErase(var Ok: WordBool);
procedure OnDoneBurn(var StatusCode: NERO_BURN_ERROR);
procedure OnAborted(var Abort: WordBool);
procedure OnDoneImport(var Ok: WordBool; var Folder: INeroFolder; var CDStamp: INeroCDStamp);
procedure OnMajorPhase(var phase: NERO_MAJOR_PHASE);
procedure OnSubTaskProgress(var ProgressInPercent: Integer; var Abort: WordBool);
procedure OnDoneWaitForMedia(var Success: WordBool);
procedure OnDoneCDInfo(const pCDInfo: INeroCDInfo);
procedure OnDoneImport2(bOk: WordBool; const pFolder: INeroFolder;
const pCDStamp: INeroCDStamp;
const pImportInfo: INeroImportDataTrackInfo;
importResult: NERO_IMPORT_DATA_TRACK_RESULT);
procedure OnDriveStatusChanged(driveStatus: NERO_DRIVESTATUS_RESULT);
procedure OnDoneEstimateTrackSize(bOk: WordBool; BlockSize: Integer);
procedure OnDoneBAOCreateHandle(StatusCode: NERO_BURN_ERROR);
procedure OnDoneBAOWriteToFile(StatusCode: NERO_BURN_ERROR; lNumberOfBytesWritten: Integer);
procedure OnDoneBAOCloseHandle(StatusCode: NERO_BURN_ERROR);
end;

const IID_DRIVEEVENTS : TGUID = ‘{7DC919C5-94D3-11D4-821C-D08D42000000}’;

type
TNeroDriveEvents = class(TObject, IDispatch)
private
FInvokableObj : INeroDriveEvents;
FCon : integer;
FSource : INeroDrive;
protected
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
public
property InvokableObject : INeroDriveEvents read FInvokableObj write FInvokableObj;

constructor Create(source : INeroDrive);
destructor Destroy; override;

end;

implementation

uses
Windows, ActiveX, SysUtils, ComObj;
{ TNeroDriveEvents }

function TNeroDriveEvents.GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
begin
Result := E_NOTIMPL;
end;

function TNeroDriveEvents.GetTypeInfo(Index, LocaleID: Integer;
out TypeInfo): HResult;
begin
Result := E_NOTIMPL;
end;

function TNeroDriveEvents.GetTypeInfoCount(out Count: Integer): HResult;
begin
Count := 0;
Result := S_OK;
end;

// funcionality mostly cpied from TOleServer
function TNeroDriveEvents.Invoke(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer): HResult;
var
ParamCount, I: integer;
VarArray : Array of OleVariant;
intVal : integer;
retVal : WordBool;
txt : WideString;
textType : NERO_TEXT_TYPE;
neroBurnError : NERO_BURN_ERROR;
folder : INeroFolder;
cdStamp : INeroCDStamp;
neroPhase : NERO_MAJOR_PHASE;
neroCDInfo : INeroCDInfo;
neroImportInfo: INeroImportDataTrackInfo;
importResult: NERO_IMPORT_DATA_TRACK_RESULT;
driveStatus : NERO_DRIVESTATUS_RESULT;
begin
Result := S_OK;
// Get parameter count
ParamCount := TDispParams(Params).cArgs;
// Set our array to appropriate length
SetLength(VarArray, ParamCount);
// Copy over data
for I := Low(VarArray) to High(VarArray) do
VarArray[High(VarArray)-I] := OleVariant(TDispParams(Params).rgvarg^[I]);

 try
    // Invoke call on object
    if FInvokableObj <> nil then
    begin
         // call correct proc
         case DispID of
           1: begin
                   intVal := VarArray[0];
                   retVal := VarArray[1];
                   FInvokableObj.OnProgress(intVal, retVal);
                   VarArray[1] := retVal;
              end;
           2: begin
                   textType := VarArray[0];
                   txt := VarArray[1];
                   FInvokableObj.OnAddLogLine(textType, txt);
              end;
           3: begin
                   txt := VarArray[0];
                   FInvokableObj.OnSetPhase(txt);
              end;
           4: begin
                   retVal := VarArray[0];
                   FInvokableObj.OnDisableAbort(retVal);
                   VarArray[0] := retVal;
              end;
           5: begin
                   intVal := VarArray[0];
                   FInvokableObj.OnWriteDAE(intVal, VarArray[1]);
                   VarArray[0] := intVal;
              end;
           6: begin
                   retVal := VarArray[0];
                   FInvokableObj.OnDoneDAE(retVal);
                   VarArray[0] := retVal;
              end;
           7: begin
                   retVal := VarArray[0];
                   FInvokableObj.OnDoneErase(retVal);
                   VarArray[0] := retVal;
              end;
           8: begin
                   neroBurnError := VarArray[0];
                   FInvokableObj.OnDoneBurn(neroBurnError);
                   VarArray[0] := neroBurnError;
              end;
           9: begin
                   retVal := VarArray[0];
                   FInvokableObj.OnAborted(retVal);
                   VarArray[0] := retVal;
              end;
           10:begin
                   retVal := VarArray[0];
                   Supports(VarArray[1], INeroFolder, folder);
                   Supports(VarArray[2], INeroCDStamp, cdStamp);
                   FInvokableObj.OnDoneImport(retVal, folder, cdStamp);
                   VarArray[0] := retVal;
              end;
           11:begin
                   neroPhase := VarArray[0];
                   FInvokableObj.OnMajorPhase(neroPhase);
              end;
           12:begin
                   intVal := VarArray[0];
                   retVal := VarArray[1];
                   FInvokableObj.OnSubTaskProgress(intVal, retVal);
                   VarArray[1] := retVal;
              end;
           13:begin
                   retVal := VarArray[0];
                   FInvokableObj.OnDoneWaitForMedia(retVal);
                   VarArray[0] := retVal;
              end;
           14:begin
                   Supports(VarArray[0], INeroCDInfo, neroCdInfo);
                   FInvokableObj.OnDoneCDInfo(neroCdInfo);
              end;
           15:begin
                   retVal := VarArray[0];
                   Supports(VarArray[1], INeroFolder, folder);
                   Supports(VarArray[2], INeroCDStamp, cdStamp);
                   Supports(VarArray[3], INeroImportDataTrackInfo, neroImportInfo);
                   importResult := VarArray[4];
                   FInvokableObj.OnDoneImport2(retVal, folder, cdStamp, neroImportInfo, importResult);
              end;
           16:begin
                   driveStatus := VarArray[0];
                   FInvokableObj.OnDriveStatusChanged(driveStatus);
              end;
           17:begin
                   retVal := VarArray[0];
                   intVal := VarArray[1];
                   FInvokableObj.OnDoneEstimateTrackSize(retVal, intVal);
              end;
           18:begin
                   neroBurnError := VarArray[0];
                   FInvokableObj.OnDoneBAOCreateHandle(neroBurnError);
              end;
           19:begin
                   neroBurnError := VarArray[0];
                   intVal := VarArray[1];
                   FInvokableObj.OnDoneBAOWriteToFile(neroBurnError, intVal);
              end;
           20:begin
                   neroBurnError := VarArray[0];
                   FInvokableObj.OnDoneBAOCloseHandle(neroBurnError);
              end;
         else
             Result := E_NOTIMPL;
         end;
    end;
 except
       Result := E_UNEXPECTED;
 end;

 // Clean array
 SetLength(VarArray, 0);

end;

function TNeroDriveEvents._AddRef: Integer;
begin
Result := 1;
end;

function TNeroDriveEvents._Release: Integer;
begin
Result := 1;
end;

function TNeroDriveEvents.QueryInterface(const IID: TGUID;
out Obj): HResult;
begin
Result := E_NOINTERFACE;

 //If events interface requested, return IDispatch
 if IsEqualIID(IID, IID_DRIVEEVENTS) then
 begin
      if GetInterface(IDispatch, Obj) then
         Result := S_OK
 end
 else
     //Handle other interface requests normally
     if GetInterface(IID, Obj) then
        Result := S_OK

end;

constructor TNeroDriveEvents.Create(source: INeroDrive);
var intf : IUnknown;
begin
inherited Create;

 FSource := source;

 QueryInterface(IID_DRIVEEVENTS, intf);

 // now connect the the nero drive object
 InterfaceConnect(FSource, _INeroDriveEvents, intf, FCon);

end;

destructor TNeroDriveEvents.Destroy;
begin
// disconnect events
InterfaceDisconnect(FSource, IID_DRIVEEVENTS, FCon);

 inherited;

end;

end.

Forget what I wrote.

There is a nice website where a tool for such things is available:

http://www.techvanguards.com/products/eventsinkimp/