Besoin d'aide pour traiter le résultat d'une dll c++

Signaler
Messages postés
12
Date d'inscription
vendredi 24 janvier 2003
Statut
Membre
Dernière intervention
8 février 2010
-
Messages postés
12
Date d'inscription
vendredi 24 janvier 2003
Statut
Membre
Dernière intervention
8 février 2010
-
Bonsoir,
J'ai une Dll ou j'aimerais pouvoir traiter le resultat d'une de ses fonction mais je ne comprends pas comment le traité en delphi.

Voici le code source de cette fonction :
size_t wordChars = wcslen( word );
char * word_buffer = handle->GetWordBuffer(word);
int wordBufferSize = strlen( word_buffer );


mentry * meanings;
DWORD count = handle->Lookup(word_buffer, wordBufferSize, &meanings );

if (count) 
{
mentry * meaning = meanings;
size_t bufferSize = sizeof(void ** ); // Meanings Count
for (int  i=0; i < count; i++) 
{
bufferSize += sizeof(void ** ); // Ptr to Meaning Data
bufferSize += sizeof(void ** ); // Synonyms Count
bufferSize += sizeof(void ** ); // Ptr to Meanings Description 
bufferSize += meaning->count * sizeof(void ** ); // Synonyms Strings

size_t meaningDescriptionWChars= MultiByteToWideChar(handle->CodePage,0,meaning->defn,-1,0,0);
bufferSize += meaningDescriptionWChars * sizeof(wchar_t); // Syononym String size (+ ending 0)

// synonyms += meaning->count;
for (int j=0; j < meaning->count; j++) 
{
char * synonym = meaning->psyns[j];
size_t synonymWordWChars= MultiByteToWideChar(handle->CodePage,0,synonym,-1,0,0);
bufferSize += synonymWordWChars * sizeof(wchar_t); // Syononym String size (+ ending 0)
}
++meaning;
}

BYTE * marshalBuffer = (BYTE *) handle->GetMarshalBuffer( bufferSize );
        BYTE * currentBufferPos = marshalBuffer;

*((void **) currentBufferPos) = (void *) count;
currentBufferPos += sizeof( void * );	
void ** meaningPtr = (void **) currentBufferPos;
currentBufferPos += sizeof( void **) * count;
meaning = meanings;
for (int  i=0; i < count; i++) 
{   
void ** currentMeaning = (void **) currentBufferPos;
currentBufferPos += sizeof( void * ); // Count;
currentBufferPos += sizeof( void ** ) * (meaning->count + 1); // Ptr

*meaningPtr = (void *) currentMeaning;

*currentMeaning = (void *) meaning->count;

++currentMeaning;

*currentMeaning = (void *) currentBufferPos;
++currentMeaning;
size_t meaningDescriptionWChars= MultiByteToWideChar(handle->CodePage,0,meaning->defn,-1,0,0);
            MultiByteToWideChar(handle->CodePage,0,meaning->defn,-1,(wchar_t *) currentBufferPos,meaningDescriptionWChars);
currentBufferPos += meaningDescriptionWChars * sizeof(wchar_t); 

for (int j=0; j < meaning->count; j++) 
{
*currentMeaning = (void *) currentBufferPos;
++currentMeaning;
char * synonym = meaning->psyns[j];
size_t synonymWordWChars= MultiByteToWideChar(handle->CodePage,0,synonym,-1,0,0);
MultiByteToWideChar(handle->CodePage,0,synonym,-1,(wchar_t *) currentBufferPos,synonymWordWChars);
currentBufferPos += synonymWordWChars * sizeof(wchar_t); 
}

            ++meaningPtr;
++meaning;
}
handle->CleanUpAfterLookup(&meanings,count);
return marshalBuffer;
} 

return 0;



Tous mes essais ne donne pas le resultat voulu ou ne fonctionne que dans des cas précis... pouvez vous m'eclairer sur le code delphi pour traité cette fonction ?

1 réponse

Messages postés
12
Date d'inscription
vendredi 24 janvier 2003
Statut
Membre
Dernière intervention
8 février 2010

Bonjour,
J'ai trouvé une solution mais je ne pense pas quelle soit "super" mais elle fonctionne lool
  TMyThesMeaning = record
    MeaningCount: UInt;
    Desc:         PChar;
  end;
  PMyThesMeaning    = ^TMyThesMeaning;
  TArrMyThesMeaning = array of TMyThesMeaning;
  PArrMyThesMeaning = TArrMyThesMeaning;

  TRMyThes = record
    Nb:  UInt;
    Pos: Pointer;
  end;
  PRMyThes         = ^TRMyThes;
  TMyThesSpellList = function(spell: Pointer; word: PChar): PRMyThes; cdecl;

...
function THunSpell.GetListMyThes(HandleSpell: Pointer; const word: string; Suggested: TStrings; Func: TMyThesSpellList): boolean;
var
  lst:  PRMyThes;
  i, j: integer;
  NbTherme: integer;
  NbSyn: integer;
  PInit: integer;
  Syn: string;
begin
  lst := Func(HandleSpell, PChar(word));
  if lst <> nil then
  begin
    NbTherme := lst^.nb;
    PInit := integer(lst^.pos);

    for I := 0 to NbTherme - 1 do
    begin
      NbSyn := PArrMyThesMeaning(pointer(PInit))[0].MeaningCount;
      Suggested.Add(PArrMyThesMeaning(pointer(PInit))[0].Desc); //Ajoute le mean

      PInit := PInit + SizeOf(Char) + SizeOf(Char);
      Syn := PChar(PInit);
      PInit := PInit + Length(Syn) * SizeOf(Char) + SizeOf(Char);

      for J := 0 to NbSyn - 1 do
      begin
        Syn := PChar(PInit);
        Suggested.Add(Syn); //Ajoute le synonyme
        PInit := PInit + Length(Syn) * SizeOf(Char) + SizeOf(Char);
      end;
    end;
  end;
end;


Voilà...