System.Runtime.InteropServices.COMException using DLL from VB6

E

Erwin Sugiawan

I try to convert from VB6 to VB.NET using Jonec.dll file.
my code like this :

Public Class clsJonec
Dim WithEvents proxy As New jonec.JonecProxy
Dim FIXDef As New jonec.JonecDef

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Private Sub proxy_OnReceiveMsg(ByVal mMsg As jonec.JonecFieldGroup)
Handles proxy.OnReceiveMsg

End Sub
End Class

after i run , there is an error said
'System.Runtime.InteropServices.COMException' occurred in
Jonec.JonecProxy.dll.

If I delete the event Private Sub proxy_OnReceiveMsg , the program will be
running well.
so I try to find the problem dan solution in msdn, and i found :

SYMPTOMS
When you call a COM component in Visual Basic .NET, and you use late
binding, you may receive the following error message:


An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in microsoft.visualbasic.dll. Additional information: Type
mismatch.
This behavior occurs when all the following conditions are true: . The
method that is called is a Public method in the COM component.
. The method takes a ByRef parameter of type Object.
. You use late binding to call the COM component.


RESOLUTION
To resolve this problem, convert the objects to the IDispatch type by using
the DispatchWrapper object. The DispatchWrapper object forces the objects to
be marshaled out as VT_DISPATCH. Assign the object to the DispatchWrapper
object. Do this instead of assigning the object to Nothing. You can do this
if you pass Nothing as a parameter to the constructor of DispatchWrapper.

The following code demonstrates how to complete this:
Dim obj As Object
obj = New Project1.Class1()
Dim inval As Object
'Marshal the object before passing it to the method.
inVal = New System.Runtime.InteropServices.DispatchWrapper(Nothing)
obj.MyFunc(inval)..........After i read it, i still don't understand,
anyone plx help me .ThxErwin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top