I have a vb6 COM object that I am converting to VB.Net 2012
My sample code looks like below :
Dim ObjContext ,objx ,objy As Object
Dim Rs As ADODB.Recordset
Set ObjContext = GetObjectContext
Set objx =ObjContext.CreateInstance("abc.class1")
Set Objy = ObjContext.CreateInstance("abcde.class2")
Set Rs = objx.getvalue(query)
If Rs.EOF And Rs.BOF Then
ObjContext.SetAbort
Set objx = Nothing
Set ObjContext = Nothing
Set Objy = Nothing
End If
What is the equivalent of GetObjectContext() and createinstance() in VB 2012?
How can i remove this concept from .net?
Try this:
I think u want this
Dim ObjContext ,objx ,objy As Object
Dim Rs As ADODB.Recordset
Set ObjContext = GetObjectContext
Dim ObjContext As COMSVCSLib.ObjectContext
Dim objAppServer As New COMSVCSLib.AppServer
ObjContext = objAppServer.GetObjectContext()
Set objx =ObjContext.CreateInstance("abc.class1")
Set Objy = ObjContext.CreateInstance("abcde.class2")
Set Rs = objx.getvalue(query)
If Rs.EOF And Rs.BOF Then
ObjContext.SetAbort
Set objx = Nothing
Set ObjContext = Nothing
Set Objy = Nothing
End If
ObjectContext.CreateInstance goes way (way) back to Microsoft Transaction Server (MTS). It seems that in COM+ it's no longer necessary to create objects via the object context. Under COM+, regular CreateObject() does the right thing.
I found this information here: http://blogs.msdn.com/b/deva/archive/2012/01/19/com-mts-custom-application-createobject-or-createinstance.aspx.
In case that blog should disappear, here are the contents verbatim:
Recently i was working with a developer customer, who created an Visual Basic/COM+ based solution (internally uses the Microsoft Messaging library). In general, he wants to know whether they should use CreateObject or CreateInstance? Whether both will have the same or different same effect in COM+?
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. So, CreateObject and CreateInstance have the same effect in COM+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With