By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Interfacing with COM from .NET

P: n/a
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.

- MM
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
However, I am getting an exception
when I try to do the following in my form:
What exception?

What do I need to do to be able to pass a .NET object that implements
a VB6 interface back to a VB6 Component?


It should "just work".

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2

P: n/a
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 Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Application.Exit()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As New ADMB003.CADMB003Class()
Dim x As New Class1()

obj.DoHandle(x)
End Sub
End Class
-------
(Class1.vb)

Public Class Class1
Implements ADMB003.IADMB003

Public Function DoProcess(ByVal str As String) As Integer Implements
ADMB003.IADMB003.DoProcess
Return Len(str)
End Function
End Class
-------
VB COM:

(CADMB003.vb)

Public Function DoHandle(ByRef obj As IADMB003) As Long
' just return junk
DoHandle = obj.DoProcess("this is a test") * 2
End Function
-------
(IADMB003.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.

HELP! :-)

I even created a similar scenario where by
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<#c**************@TK2MSFTNGP10.phx.gbl>...
However, I am getting an exception
when I try to do the following in my form:


What exception?

What do I need to do to be able to pass a .NET object that implements
a VB6 interface back to a VB6 Component?


It should "just work".

Mattias

Nov 20 '05 #3

P: n/a
Incidentally, on the code I just submitted, I am getting a
NullReferenceException on the Button1_Click sub on the line that
actually calls "DoHandle". I have checked both objects in previous
tests and both of them are indeed set to references. I believe it may
be something wrong with passing .NET objects to COM. I have to be
missing something...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As New ADMB003.CADMB003Class()
Dim x As New Class1()

obj.DoHandle(x) <= NullReferenceException
End Sub

Mattias Sjögren <ma********************@mvps.org> wrote in message news:<#c**************@TK2MSFTNGP10.phx.gbl>...
However, I am getting an exception
when I try to do the following in my form:


What exception?

What do I need to do to be able to pass a .NET object that implements
a VB6 interface back to a VB6 Component?


It should "just work".

Mattias

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.