Link to home
Start Free TrialLog in
Avatar of ws1999
ws1999

asked on

about buffer

ask this question for my friend,his code:

var
   Buffer: Pointer;
begin
 Buffer := Pointer(LocalAlloc( LPTR, dwSizeofDataToWrite+1 ));

He told me that when use locafree, error message is found.

How to solve this problem, buffer cannot use localfree?
Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

Hi!

This works for me:

var
   Buffer : Pointer;
begin
  Buffer := Pointer( LocalAlloc( LPTR, 1024 ) );

  LocalFree( Cardinal(Buffer) );
end;
var
  ptr : pointer;
begin
ptr := pointer(LocalAlloc(lptr, 1024));
lstrcpy(ptr, 'I was here!');
ShowMessage(pchar(ptr));
LocalFree(cardinal(ptr));
end;

Work's fine. Allocates, writes, reads, frees - no problems...
what is that error message?

are you sure you don't try to free the buffer twice?
Avatar of ws1999
ws1999

ASKER

Sorry for late reply, the problem indeed comes from the thread using, the question is, is it possible before the main thread completed setup, the child thread can take function?

Sorry again, and 50 ponts added.




ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial