INFO: CreateObject and CreateInstance Have the Same Effect in COM+ (250865)



The information in this article applies to:

  • Microsoft COM+ 1.0
  • Microsoft COM+ 1.5

This article was previously published under Q250865

SUMMARY

In Microsoft Transaction Server (MTS), you must use ObjectContext.CreateInstance in your root object to create secondary objects for the transaction to flow. In COM+ this still works, but it is no longer necessary to do it. In COM+, CreateObject subsumes the functionality of ObjectContext.CreateInstance. The object created participates in the caller's activity.

In COM+, you can use the standard CreateObject function in Microsoft Visual Basic to flow a transaction to secondary objects as appropriate.

The following example shows how the root object (clsRoot) creates the secondary object (clsSec) from within a transactional object.
Sub Test()
  Dim objSec As clsSec  'clsSec is the secondary class.
  Set objSec = CreateObject ("prjTest.clsSec")
End Sub
				
Also note that in COM+, as opposed to Microsoft Transaction Server, you don't have to obtain the ObjectContext in this particular scenario. This applies to CoCreateInstance and CoCreateInstanceEx APIs in C++ also.

Modification Type:MajorLast Reviewed:2/20/2002
Keywords:kbDSupport kbinfo KB250865