Link to home
Start Free TrialLog in
Avatar of emily_hall
emily_hall

asked on

COM library question

I have a library that I made to interact with my VB program.  It is the first time I have done this so I am a bit unclear on the whole COM library thing.  Anyway - I made this library and it works fine with one huge problem - I call one function in the library and set some member variables, assign some values to things and then a bit later I call another function that tries to use these values and they are ALWAYS messed up.  Is there some reason that I can't do this?  How can I make 1 variable and an array that will stay through the time that I am using the library?

My member variable is just a counter that is set in the function Constructor.  When I try to access the same variable through the function Update it is hosed.  The array is an array of a class that I made that are allocated with the new operator - which leaves a huge memory leak since when I come back to delete them they've dissapeared somewhere and I can't access them.

Thanks
Emily
ASKER CERTIFIED SOLUTION
Avatar of weary
weary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weary
weary

Here is an example of some VB code, that both is a COM object and uses a COM object. This code is within a class module in VB. Keep in mind I don't know much about VB, but rather C++.

Implements IPlugin

Private Sub IPlugin_Execute(ByVal pAppAutomation As Object)

Dim test As IAppAutomation
Set test = pAppAutomation

Dim bSuccess As Boolean
bSuccess = test.UpdateSomething("String to set")

End Sub

In this case the COM object that I use is passed into the method, so it doesn't need to be saved anywhere. This code is actually called by a C++ program, that passes it's automation interface to the VB dll. The VB dll, then calls methods on that object.

Normally in VB, you would have to create an object, make some calls to store data, and then save the object for future access to the data.

Anyway. hope this helps.
Avatar of DanRollins
I agree with weary.  I think that you are allowing the object to be destroyed and then the next time you look at it, you are looking at a new copy of it (no way to know without further description and without seeing some code).

-- Dan
Avatar of emily_hall

ASKER

D'OH!  i wasn't even aware i was doing that but indeed i was creating a new object every time i tried to call the code.  thanks!


emily