How to return a PCHAR string greater than 4K from the DLL

xiaoxiao2021-03-06  69

About: "How to return a PCHAR string greater than 4K from DLL"

Shalow is available in 2004-5-27 16:08:17, please check and evaluate: --------------------------- -------------------------------------------------- I have seen your program, in fact, you haven't passed all, because the string you want to pass is released in Xs_StringList.Destroy, so you have access to illegal memory in the main program. The following: Function Rundll: pchar; stdcall; var xs_stringlist: tstringlist; // List system settings DD: Integer; N: INTEGER; begin xs_stringlist: = tstringlist.create; xs_stringlist.text: = '

; for Dd: = 1 to 300 do xs_stringlist.text: = xs_stringlist.text ' DDDFGDFDGDDDDDDDDDDDDDD DFSSFDGSDFASSDFDFSD ' INTOSTR (DD) ' '; xs_stringlist.text: = xs_stringlist.text ' ';

// Repair this part N: = Length (xs_stringlist.text); Result: = allocmem (n 1); try move (xs_stringlist.text [1], result ^, n); // must remember in calling Rundll The function of the function is used to release this return value with the FreeMem function, or the memory leak // Except FreeMem (Result: = nil; end; //Result:=pchar(XS_StringList.text); xs_stringlist.destroy ;

// Example of call Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR P: ​​Pchar; Begin P: = Rundll; Try if P <> nil damo1.Lines.Add (String (p)); Finally FreeMem (P) END;

转载请注明原文地址:https://www.9cbs.com/read-109474.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.033, SQL: 9