PDA

View Full Version : deallocating memory from within VB


grossd
01-16-2003, 09:17 PM
Hello,

After receiving a pointer from a C DLL that points to a C struct, is it possible to dallocate the struct from within VB.

Stated differently, can i do a free() from within VB by doing some sort of Declare defintions.

One problem might be that i don't know how many bytes were actually allocated within a C DLL for the struct.


appreciating any help

Daniel

OnErr0r
01-16-2003, 09:39 PM
On the VB side there is no "new" function. So VB takes care of deallocating memory. If you're talking about on the C++ side, you could create an exported function that calls delete, if its a dynamically allocated struct. Or just do it in the DllEntryPoint on DLL_PROCESS_DETACH.

grossd
01-16-2003, 09:49 PM
Thank you for your prompt replies.


Yes i thought about exporting a function that frees an Answer structure. Actually, because i don't have the source code for the C DLL, i will create my own DLL with this one exported function.


I hoped that i can do it without resorting to C DLL programming ...


many thanks for the most helpful suggestions ...

Daniel


ps. Its a pity i can't somehow hook the pointer to the structure into the garbage collection of VB itself ...