?
Solved

Memory deallocation

Posted on 2004-03-31
6
Medium Priority
?
872 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
MePhantom earned 300 total points
ID: 10729837
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
ID: 10729929
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 300 total points
ID: 10729953
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 28

Assisted Solution

by:Ark
Ark earned 75 total points
ID: 10729957
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
ID: 10729990
Thanks a lot guys, really appreciate it :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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