Solved

Memory deallocation

Posted on 2004-03-31
6
867 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
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 100 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 25 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Access combo box help 2 49
Visual Studio 2005 text editor 10 43
Problem to With line 4 63
Publisher:   Unknown     VB.exe Application 1 27
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

809 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