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
LVL 1
emily_hallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wearyCommented:
Without any code I'm not sure I can say exactly what the problem is. First, is this library a COM DLL?  Second, which language is the library written in, and which language are you using the library from?

It sounds like you are using a COM DLL written in C++ in your VB project.

When you create a COM object in C++, it's pretty similar to a normal C++ class. You can have member variables that store state for that class, and different methods can change these variables. One thing that might cause you to lose this information, is if you are create a new COM object every time you want to access the variables. Make sure you create an instance of your class once, and store it somewhere, so you can access it later.

If this isn't the problem, then I think I would need to see some code of how you access the COM object, and possibly the code from within the COM object that modifies the variables.

Hope this helps.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wearyCommented:
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.
0
DanRollinsCommented:
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
0
emily_hallAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.