Solved

Memory deallocation

Posted on 2004-03-31
6
866 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 27

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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