======================================== Let's say that the code behind for the aspx page looks like this: ======================================== Imports Project1 Imports System Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer
Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the
Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim obj As New Project1.Math() Response.Write(obj.Add(1,
2)) Response.Write(obj.AddCom(1, 4)) End Sub End Class ============================ and the VB6 COM Math class looks like this: ============================ Option Explicit Public Function AddCom(x As Integer, y As Integer) As Integer Dim Context As COMSVCSLib.ObjectContext
Dim Response As ASPTypeLibrary.Response Set Context = GetObjectContext() Set Response = Context("Response") AddCom = x + y Response.Write x Context.SetComplete Set Context = Nothing Set Response = Nothing End Function Public Function Add(x As Integer, y As
Integer) As Integer Add = x + y End Function ====================================================== The "Add" Function works fine but the "AddCom" function returns the following error: ====================================================== Object required
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException:
Object required Source Error: Line 24: Dim obj As New Project1.Math() Line 25: Response.Write(obj.Add(1, 2)) Line 26: Response.Write(obj.AddCom(1, 4)) Line 27: End Sub Line 28: Source File: c:\inetpub\wwwroot\DotNetPortal\WebForm1.aspx.vb Line: 26 Stack Trace:
[COMException (0x800a01a8): Object required] Project1.MathClass.AddCom(Int16& x, Int16& y) +0 DotNetPortal.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\DotNetPortal\WebForm1.aspx.vb:26 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive()
+29 System.Web.UI.Page.ProcessRequestMain() +724 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET Version:1.0.3705.288 ======================================================
Is it possible to do this? If so, how? The reason is that I have some legacy code in VB6 Components that use the request/response/server/application objects that I would like to reuse if possible. Otherwise it looks like a rewrite? ======================================================
Try this: Option Explicit Public Function AddCom(x As Integer, y As Integer) As Integer Dim Context As COMSVCSLib.ObjectContext DIM Appserver as COMSVCSLib.Appserver Dim Response As ASPTypeLibrary.Response Set Context = Appserver.GetObjectContext() Set Response
= Context("Response")
You will need to set the Page directive to AspCompat so the Aspx is single threaded, Response.Write( string s) etc if your component returns integer values etc there will be no problem as its a CLR type, check the component has been created.
Line 24: Dim obj As New Project1.Math()
Line 25: Response.Write(obj.Add(1, 2)) <- what is written to Response.Write ? Is it an integer ??
Line 26: Response.Write(obj.AddCom(1, 4))
Line 27: End Sub
Line 28:
hhhhh
Member
15 Points
3 Posts
Calling a VB6 COM that uses ASP context to access the Request/Response objects?
Nov 06, 2002 08:05 PM|LINK
hhhhh
Member
15 Points
3 Posts
Re: Calling a VB6 COM that uses ASP context to access the Request/Response objects?
Nov 07, 2002 11:37 AM|LINK
hhhhh
Member
15 Points
3 Posts
More details - is this possible - or am i just stoopid?
Nov 07, 2002 12:23 PM|LINK
jotenks
Member
10 Points
2 Posts
Re: More details - is this possible - or am i just stoopid?
Feb 21, 2003 03:23 PM|LINK
ojm37
Contributor
2248 Points
832 Posts
Re: More details - is this possible - or am i just stoopid?
Jun 17, 2004 08:15 PM|LINK
teststand
Member
375 Points
75 Posts
Re: More details - is this possible - or am i just stoopid?
Jun 20, 2004 06:17 PM|LINK