Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing pointers to pointers
Message
De
27/08/2004 03:01:01
 
 
À
Tous
Information générale
Forum:
Delphi
Catégorie:
Code Syntaxe & Commandes
Titre:
Passing pointers to pointers
Divers
Thread ID:
00936892
Message ID:
00936892
Vues:
85
I'm using delphi functions in my dll, which is dynamically loaded into someone else's host program. The C++ SDK for the host has been translated to Delphi by someone else. The host calls getChunk() and setChunk() at particular times, and I must supply or receive an amount of data, respectively. The data is meaningful to me but an opaque chunk to the host.

These are the functions:
//C++
virtual long getChunk (void** data, bool isPreset = false) { return 0; }
virtual long setChunk (void* data, long byteSize, bool isPreset = false) { return 0; }

//Delphi
function getChunk(var data: pointer; isPreset: Boolean): longint; virtual;
function setChunk(data: pointer; byteSize: longint; isPreset: Boolean): longint; virtual;
I'm noting that data in getChunk is a pointer to a pointer, so has been declared in Delphi as a variable parameter so it is passed by reference. I thought this meant that I didn't need to allocate a variable of type ^pointer and fill it with @programs and set data to it's address. But I'm not sure. Anyway, this (edited down) is what I have tried to write. But I'm finding that the messagebox in setChunk() is displaying 'cleared', where it should be displaying 'saved'. Now I'm wondering if I should be allocating memory outside these functions and filling the memory and passing pointers to that inside the functions.

Where am I going wrong, please?
//Interface

type

 kNumPrograms  = 16;

 APluginProgram=class
 private
    fpar: Tfpar;
    name: array[0..50] of char;
    expression: array[0..254] of char;
    ...

 Tprograms = array[0..kNumPrograms-1] of APluginProgram;

 APlugin=class(AudioEffectX)
 public
   function getChunk(var data: pointer; isPreset: Boolean): longint; override;
   function setChunk(data: pointer; byteSize: longint; isPreset: Boolean): longint; override;
   ...


//Implementation
...

function APlugin.getChunk(var data: pointer; isPreset: Boolean): longint;
begin
 inherited getChunk(data, isPreset);
 programs[curprogram].expression := 'saved';
 data := @programs;
 Result := SizeOf(programs);
end;

function APlugin.setChunk(data: pointer; byteSize: longint; isPreset: Boolean): longint;
begin
 inherited setChunk(data, byteSize, isPreset);
 if byteSize <> SizeOf(programs) then begin Result := 1; exit; end;
 programs[curprogram].expression := 'cleared';
 programs := Tprograms(data^);
 MessageBox(0, PChar('programs[curprogram].expression = '
   + programs[curprogram].expression), Nil, MB_OK);
 Result := 1;
end;
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform