COM library question

Posted on 2003-02-21
Medium Priority
Last Modified: 2013-12-14
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.

Question by:emily_hall
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

Accepted Solution

weary earned 800 total points
ID: 7994321
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.


Expert Comment

ID: 7994448
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.
LVL 49

Expert Comment

ID: 7994690
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

Author Comment

ID: 7996489
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!


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 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