Board index » delphi » Allocating memory in a C++-DLL - Freeing it in a Delphi 3 Application

Allocating memory in a C++-DLL - Freeing it in a Delphi 3 Application

Hello,

I've written a DLL in Borland C++ 5.0.  One of the functions is a simple
concatenation function :

char* __stdcall _export StringTest(char* Str1, char* Str2)
{
   char* tmp;

   int l1 = strlen(Str1);
   int l2 = strlen(Str2);

   tmp = (char*) malloc(l1+l2+1);
   strcpy(tmp, Str1);
   strcat(tmp,Str2);
   return tmp;

Quote
}

This function works fine, but it has a memory leak : the memory
allocated for tmp is not released.

This function is called from a Delphi 3 application.  Can anyone tell me
how I can release the allocated memory, prefarably from the Delphi
application ?
I've tried freeing the memory just before the return instruction, but it
doesn't work.

Thanks in advance,

Johan

 

Re:Allocating memory in a C++-DLL - Freeing it in a Delphi 3 Application


In comp.lang.pascal.borland, Johan Vervoort spluttered:

Quote
>I've written a DLL in Borland C++ 5.0.  
>This function is called from a Delphi 3 application.

Try asking in a Dephi newsgroup for Delphi help.

From Timo's *weekly* posting:

CURRENT:
 comp.lang.pascal.ansi-iso Pascal according to ANSI and ISO standards.
 comp.lang.pascal.borland  Borland's Pascal incl. Turbo Pascal (not Delphi!)
 comp.lang.pascal.mac      Macintosh based Pascals.             ^^^^^^^^^^^
 comp.lang.pascal.misc     Pascal in general and ungrouped Pascals.

 comp.lang.pascal.delphi.advocacy Contentious issues related to Delphi.
 comp.lang.pascal.delphi.announce Delphi related announcements. (Moderated)
 comp.lang.pascal.delphi.components.misc General component issues.
 comp.lang.pascal.delphi.components.usage Using pre-written components.
 comp.lang.pascal.delphi.components.writing Writing Delphi components.
 comp.lang.pascal.delphi.databases Database aspects of Borland Delphi.
 comp.lang.pascal.delphi.misc General issues with Borland Delphi.
 comp.sources.delphi Delphi and ObjectPascal source code. (Moderated)

OLD:  Please cease using!
 comp.lang.pascal                     Discussion about Pascal.
 comp.lang.pascal.delphi.components   Writing components in Borland Delphi.

--
Pedt Scragg

Never challenge a porcupine to an ass-kicking contest

Re:Allocating memory in a C++-DLL - Freeing it in a Delphi 3 Application


Quote
Johan Vervoort wrote:
> This function is called from a Delphi 3 application.  Can anyone tell me
> how I can release the allocated memory, prefarably from the Delphi
> application ?
> I've tried freeing the memory just before the return instruction, but it
> doesn't work.

How about allocating the memory in Delphi, handling the adress over to the
function and then freeing  the memory in Delphi?

    Bye,
      Ingo

Other Threads