M
Michael M
All,
I have a silly issue that I'd like to handle. I am certain there is a
way to do this, but I can't seem to figure it out...so please help.
I have to VB6 objects that I'm working with:
CController
IHandler
IHandler is a VB6 "inteface" that declares a method (sub) "DoProcess"
CController is your basic object that has a method (sub) "DoHandle".
This DoHandle method expects a parameter of (ByRef) IHandler like so:
public sub DoHandle(ByRef objHandler as IHandler)
Within the DoHandle method in CController, the "DoProcess" method if
the implemented IHandler is called.
My .NET application has 1 class and one form.
the Class, CHandler, successfully implements the IHandler and the
IHandler.DoProcess method.
The form creates an instance of the CControllerClass and an instance
of the new .NET CHandler class. However, I am getting an exception
when I try to do the following in my form:
public sub cmdProcess_Click(...)
dim objController as new CControllerClass()
dim objHandler as new CHandler()
objController.DoHandle(objHandler) <= throws an exception
end sub
When the new CController tries to process the DoHandle method, it
bombs out.
What do I need to do to be able to pass a .NET object that implements
a VB6 interface back to a VB6 Component?
Any assistance will be greatly appreciated.
The exception I am getting is a NullReferenceException.
I have double checked my code and even created a test project with a
similar set up...to no avail...am I missing something?
Here is the code that I have:
-------
..NET:
-------
(Form1.vb)
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdExit.Click
Application.Exit()
End Sub
Private Sub cmdProcess_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmdProcess.Click
Dim obj As New ADMB003.CControllerClass()
Dim x As New Class1()
obj.DoHandle(x) ' <= Throws NullReferenceException...WHY?
End Sub
End Class
-------
(Class1.vb)
Public Class Class1
Implements ADMB003.IHandler
Public Function DoProcess(ByVal str As String) As Integer Implements
ADMB003.IHandler.DoProcess
Return Len(str)
End Function
End Class
-------
VB COM (Project name is ADMB003:
(CController.vb)
Public Function DoHandle(ByRef obj As IHandler) As Long
' just return junk
DoHandle = obj.DoProcess("this is a test") * 2
End Function
-------
(IHandler.vb - public not createable interface)
Public Function DoProcess(ByVal str As String) As Long
' to be implemented by child class
End Function
-------
The code in Class1 is as is...Am I missing something? I totally
thought this would be as simple as doing just what I did above, but I
seem to be having issues.
I am currently using Visual Studio .NET (not Visual Studio .NET 2003)
and 1.1 version of the .NET Framework.
HELP!
I have a silly issue that I'd like to handle. I am certain there is a
way to do this, but I can't seem to figure it out...so please help.
I have to VB6 objects that I'm working with:
CController
IHandler
IHandler is a VB6 "inteface" that declares a method (sub) "DoProcess"
CController is your basic object that has a method (sub) "DoHandle".
This DoHandle method expects a parameter of (ByRef) IHandler like so:
public sub DoHandle(ByRef objHandler as IHandler)
Within the DoHandle method in CController, the "DoProcess" method if
the implemented IHandler is called.
My .NET application has 1 class and one form.
the Class, CHandler, successfully implements the IHandler and the
IHandler.DoProcess method.
The form creates an instance of the CControllerClass and an instance
of the new .NET CHandler class. However, I am getting an exception
when I try to do the following in my form:
public sub cmdProcess_Click(...)
dim objController as new CControllerClass()
dim objHandler as new CHandler()
objController.DoHandle(objHandler) <= throws an exception
end sub
When the new CController tries to process the DoHandle method, it
bombs out.
What do I need to do to be able to pass a .NET object that implements
a VB6 interface back to a VB6 Component?
Any assistance will be greatly appreciated.
The exception I am getting is a NullReferenceException.
I have double checked my code and even created a test project with a
similar set up...to no avail...am I missing something?
Here is the code that I have:
-------
..NET:
-------
(Form1.vb)
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdExit.Click
Application.Exit()
End Sub
Private Sub cmdProcess_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmdProcess.Click
Dim obj As New ADMB003.CControllerClass()
Dim x As New Class1()
obj.DoHandle(x) ' <= Throws NullReferenceException...WHY?
End Sub
End Class
-------
(Class1.vb)
Public Class Class1
Implements ADMB003.IHandler
Public Function DoProcess(ByVal str As String) As Integer Implements
ADMB003.IHandler.DoProcess
Return Len(str)
End Function
End Class
-------
VB COM (Project name is ADMB003:
(CController.vb)
Public Function DoHandle(ByRef obj As IHandler) As Long
' just return junk
DoHandle = obj.DoProcess("this is a test") * 2
End Function
-------
(IHandler.vb - public not createable interface)
Public Function DoProcess(ByVal str As String) As Long
' to be implemented by child class
End Function
-------
The code in Class1 is as is...Am I missing something? I totally
thought this would be as simple as doing just what I did above, but I
seem to be having issues.
I am currently using Visual Studio .NET (not Visual Studio .NET 2003)
and 1.1 version of the .NET Framework.
HELP!