miércoles, 11 de julio de 2012 23:30
I have main application written in Visual Basic 6.0, and the sub module in Visual Studio 2008(C#.NET). When I tried to call .NET form from VB 6.0 it works fine, and when I tried to raise an event in VB 6.0 from .NET then it just executes but then event doesn't raise. And it don't throw any exception too.
I am completely frustrated with it from a week, kindly anyone can help me on this.
Thanks in advance
Todas las respuestas
viernes, 13 de julio de 2012 5:29Moderador
Welcome to the MSDN forum.
I would refer to this reply by Riquel_Dong from http://social.msdn.microsoft.com/Forums/uk/vbinterop/thread/dac51bc1-ad48-48af-9342-93b8781feab5 . Basically, to fire an event from .NET,you can let VB.NET expose one public method, when we call this method from VB6. It will raises one VB.NET event. We need to add event handler in VB6 to handle this event.
Please have a look at the following code snippet. I refer to book <<COM and .NET Interoperability>> in Page 609.
VB.NET class library VbDotNetEventSender:
' This is the name of the event interface to be generated.
Public Interface _DEventInterface
<DispId(1)> Sub TheEvent(ByVal msg As String)
Public Class VbDotNetEventSender
Public Event TheEvent(ByVal msg As String)
Public Sub FireTheEvent()
RaiseEvent TheEvent("Hello from the DotNetEventSender")
VB6 code snippet:
Public WithEvents eventObj As VbDotNetEventSender.VbDotNetEventSender
Private Sub Command1_Click()
Private Sub eventObj_TheEvent(ByVal msg As String)
MsgBox msg, , "Message from event object"
Private Sub Form_Load()
Set eventObj = New VbDotNetEventSender.VbDotNetEventSender
I hope this will be helpful.
MSDN Community Support | Feedback to us
viernes, 13 de julio de 2012 21:23
First and foremost thank you so much for your precious time. As far as coding is concerned everything looks just fine.
But as I observed ApplicationEventRaisedEvent is returning null, is that fine or that might be causing the problem?
If yes what would be the possible reason could you please tell me.
miércoles, 18 de julio de 2012 20:14Yes, that was causing problem. I was getting ApplicationEventRaisedEvent as null because in two of the place it was getting Initialized in the application.