Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

COM library question

Posted on 2003-02-21
4
Medium Priority
?
304 Views
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.

Thanks
Emily
0
Comment
Question by:emily_hall
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
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.


0
 
LVL 1

Expert Comment

by:weary
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.
0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 
LVL 1

Author Comment

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


emily
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

577 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