amr elalamy wrote:
> Hi all,
>
> I want to allocate memory in DLL and free this allocation in another
> application. Is it valid or not???? i.e.
>
>
> DLL:
>
> void GetText (char * & text)
> {
> text = new char[1000];
> .......
> }
>
> EXE:
>
> void main()
> {
> char * txt = NULL;
> pGetText(txt);
> if(txt)
> delete [] txt;
>
> }
Maybe. It depends on how the application is built. If you use the VC++
"shared library" C++ runtime, then yes. If you statically link the C++
runtime, then no. The definitions of new and delete are defined in the
shared library.
Crossing EXE/DLL and even .lib boundaries with new/delete will _require_
the use of the shared library to link the application. One of the
indicators that this has occurred is the LNK2005 error message:
http://cubicspot.blogspot.com/2007/06/solving-pesky-lnk2005-errors.html
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/