Solved

Memory deallocation

Posted on 2004-03-31
6
863 Views
Last Modified: 2006-11-17
How can memory de-allocation be achieved from VB in this scenario?

VB Client
C++ dll

If I am calling a function in a C++ dll from VB with an array of User defined data type (structure in C++) as parameter[Out]. If the C++ dll allocates memory to the structure array how can I deallocate that memory in VB client.

thanks,
Rishi

0
Comment
Question by:rishikt
  • 2
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
MePhantom earned 100 total points
Comment Utility
Hi rishikt,

The dll must be VB aware and use the VB memory functions.
If it isn't then you can not allocate the array in the dll.
It will crash if you do. You could define an empty array in VB and pass it if the dll does not do a malloc.
No need to free it in VB this is automatic.
0
 

Author Comment

by:rishikt
Comment Utility
thanks for the quick reply!

So are u saying that there is no way I can allocate the memory in C++ dll and return it to VB client?
Which VB memory functions are u referring to?
0
 
LVL 2

Assisted Solution

by:MePhantom
MePhantom earned 100 total points
Comment Utility
There is a API library that you can include in the C, but its been a while and don't remember where it is.
0
 
LVL 27

Assisted Solution

by:Ark
Ark earned 25 total points
Comment Utility
The 'normal' way is to allocate memory in VB and pass a pointer to first array member as well as members count into C++ dll:
void MyFunction(LPMYSTRUCT lpUDT, int nCount){
   for (int i;i++;i<nCount){
//Fill UDTs
        lpUDT[i]->x = 1
   }
}

From VB
   Dim MyUDT(20) 'allocate memory
   Call MyFunction(MyUDT(0),21)
'No need to deallocate - VB clean up memory heap after exiting the scope
0
 

Author Comment

by:rishikt
Comment Utility
Thanks a lot guys, really appreciate it :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now