Re: new - delete issue
- From: Ale <Ale@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 10 Oct 2005 04:21:03 -0700
So, if I need to get data from a DLL - e.g. a struct:
EXE calls a DLL exported function that return a struct pointer.
DLL allocates memory for the struct and save this pointer in a list, than
return pointer to EXE.
EXE do something...
The EXE call another exported function that delete all pointers in that list.
Is it correct!? This is a really new way to follow up!!!!!
Ale
"David Wilkinson" wrote:
> Ale wrote:
>
> > Take a look at this:
> >
> > DLL, loaded into address space of main thread.
> >
> > In Main Thread:
> > MYSTRUCT *p = MYDLL.GetStruc();
> >
> > .....
> >
> > AfxIsValidAddress( p, sizeof( MYSTRUCT ) ); // Doesn't Fail
> >
> >> delete p; // Fail
> >
> >
> > MYDLL GetStruct() exported function:
> > MYSTRUCT* p = new MYSTRUCT
> > ....
> > return p;
> >
> > Really strange, delete p in Main Thread fails.
> > It fails an ASSERT : _ASSERTE(_CrtIsValidHeapPointer(pUserData)); into
> > _free_dbg
> >
> > Before performing "delete p" the pointer is OK, i've taken a look at memory
> > and everythig is OK!!!!
> >
> > Thanks
> > Ale
> >
>
> Ale:
>
> I have to say I disagree with the direction you are being pushed in
> here. If you want to use static linking you should use it. You just need
> another exported function in the DLL:
>
> void DeleteStruct(MYSTRUCT* p)
> {
> delete p;
> }
>
> Use this function to delete the object from the main thread. In any
> case, IMHO, it is not a good practice to delete an object in a different
> place from where you created it.
>
> HTH,
>
> David Wilkinson
>
>
.
- References:
- Re: new - delete issue
- From: David Wilkinson
- Re: new - delete issue
- Prev by Date: how to make 1 word bold in a MessageBox()
- Next by Date: Re: CPropertyPage Background Color Inconsistency
- Previous by thread: Re: new - delete issue
- Next by thread: Re: new - delete issue
- Index(es):
Relevant Pages
|