Solved

Memory deallocation

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

752 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