VB COM instantiation/technical details - "behind the scenes" information desired

Posted on 2003-03-09
Medium Priority
Last Modified: 2013-11-25
I have some questions regarding VB COM objects and was wondering if anyone who really understands this could answer the following questions:

1.  When I instantiate a COM object (using the new keyword or CreateObject) what really happens?  Object is created in memory?  Multiple objects are created in memory? For a COM built in VB, does the VB runtime get loaded into memory?

2.  If one client instantiates multiple object (more than one OF THE SAME OBJECT or multiple VB based COM objects) does the vb runtimes get loaded into memory multiple times?
         eg.  Set obj1 = New cObject
              Set obj2 = New cObject
              Set obj3 = New cObject
              In this scenario, what is actually loaded into memory?

3.  When a component is hosted in COM+, does the answer to question #2 change?  I know that VB is not multi-threaded and cannot have multiple objects loaded on individual threads, but can have multiple instances of an object on a single thread.  What really is the difference between multiple instances in a single thread -vs- multiple objects on multiple threads?  Just the ability to asynchronously execute methods?

I have been trying to find any documentation that can help me better understand the internals of what is going on but have been unsuccessful in my search.  Any help in better understanding the above questions would be most aprpeciated.

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

Accepted Solution

PhiliP earned 500 total points
ID: 8099658
Ok, VB always needs it's runtime.

For each new obj you'll get a new obj regardless of the class

VB is single- and appartment-threaded. All threads run in the same memory space.

If one object fails and the failure is fatal then all objects on the thread fail. The applications end's

In com or com+ the object are created in the process of the transaction manager in there own memoryspace so failure of one object is not fatal for the rest. (if created in own process)

Your assumption on asynchronously executing methods is correct. However you have to use a callback method to catch succes

Regards PhiliP

Assisted Solution

Marshawk earned 500 total points
ID: 8100768
For question 1:

When you create an object with CreateObject() or the "New" statement several ole api calls come into action, the most important of which is CoCreateInstance(). That is the api call that really creates the ole object. Ancillary ole support routines such as CLSIDFromProgID may be called when you use CreateObject.

The Visual basic loads when your VB exe file runs. If it isnt present then you will get a missing dll error of some type typically.

For Question 2:
No it is not instantiating an object that causes the VB runtime to load. The runtime loads per process, anotherwards per VB exe file. The Runtime will be loaded once for the current process regardless of whether you instantiate objects or not. When you create an object a data table of pointers is created in memory that point to the address of each method in each interface. And if the object resides in an exe (out-of-process) then the object server is loaded. I am not clear if (in-process) servers are loaded on demand or when the VB exe file loads.

Here is a link to a short Microsoft document on the subject:


Question 3:
Don't know about COM+. But it is possible to create objects that each run on their own thread from a visual basic program. They must reside in an out-of-process exe module, typically they will have the "object per thread"  checked (if created with VB) and you must use createobject to instantiate them.

You can find some good articles on the subject at:

Look for articles by Francesco Balena, Matthew Curland and William Storage. In the archives mostly 97-2000.


Expert Comment

ID: 9056491
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
LVL 49

Expert Comment

ID: 9074554
Moderator, my recommended disposition is:

    Split points between: PhiliP and Marshawk

DanRollins -- EE database cleanup volunteer

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

765 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