delphi - Calling a DLL function with more than one return values -


my dll might send more 1 result/return value exe in 1 shoot. still don't understand how make callback function dll can communicate host app.

here's scenario :

app :

type   tcheckfile = function(const filename, var info, status: string): boolean; stdcall;  var   checkfile: tcheckfile;   dllhandle: thandle;  procedure test; var info,status : string; begin .... // load dll  dllhandle := loadlibrary('test.dll');     if dllhandle <> 0     begin       @checkfile := getprocaddress(dllhandle, 'checkfile');       if assigned(checkfile)         beep       else         exit;     end;  // use function dll if assigned(checkfile)   begin     if checkfile(filename, info, status)     begin     addtolistview(filename, info, status);     end;   end; ... end; 

dll:

function checkfile(const filename, var info,status: string): boolean; stdcall;   var     info, status: string;   begin        if istherightfile(filename, info,status)     begin       result := true;       exit;     end     else     begin       if iszipfile       begin         // call function extract file         extractzip(filaname);         // check extracted file         := 0 extractedfilelist.count         begin           istherightfile(extractedfile, info, status)           // how send filename, info , status exe ?? // << edited           // sendipcmessage('checkengine', pchar('◦test'), length('◦test') * sizeof(char)); error!           // "addtolistview(filename, info);" ???         end;       end;     end;   end; 

actually still error code above. in case, need explain , determine correct way send data dll appp.

you on right lines obvious problem can see use of string variables. these heap allocated , since have 2 separate memory managers allocating on 1 heap (in dll) , freeing on different heap (in app).

there few options. 1 options share memory managers don't recommend variety of reasons. without going them state in comment want non delphi applications able use dll preclude use of shared memory manager.

another option force calling app allocate memory string , let dll copy memory. works fine labour intensive.

instead use string type can allocated in 1 module freed in different module. com bstr such type , in delphi terms widestring. change code use widestring exported functions.


i simplify importing/exporting process , use implicit dynamic linking.

dll

function checkfile(   const filename: widestring;    var info, status: widestring ): boolean; stdcall; 

app

function checkfile(   const filename: widestring;    var info, status: widestring ): boolean; stdcall; external 'test.dll';  procedure test(const filename: string); var   info, status: widestring; begin   if checkfile(filename, info, status)     addtolistview(filename, info); end; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -