473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Confused by Delegate Events

I'm confused by documentation and examples on using Delegate to create
Events for use with COM

In some situation I see a parameter list of (sender as Object, e as
EventArgs) and other times I see no parameters, or a list of parameters that
are event dependent.

Below is my .NET code to create a class which raises some events.
From C++ (using MFC 6.0) I create an instance of the object and
IConnectionPointContainer which seems to work.

When the .NET object raises the event I get an exception of type

System.NullReferenceException: Object reference not set to an instance of an
object.
at MapiForm._FormEvents.Shutdown()
at MapiForm.MAPIForm.frm_ShutDownForm() in D:\My
Documents\SQLView\Forms\MAPIForm\MAPIForm.vb:line 63
at MapiForm.OutlookForm.txtShutdown_Click(Object sender, EventArgs e) in
D:\My Documents\SQLView\Forms\MAPIForm\OutlookForm.vb:li ne 113
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

*******************

Any ideas how I need to setup events so that I can call them from MFC 6.0
???

Thanks!

******************

----------- snip -------------
Imports System
Imports System.Runtime.InteropServices

<ComVisible(False)> Public Delegate Sub NewMessageEventHandler()
<ComVisible(False)> Public Delegate Sub ShutdownEventHandler()
<ComVisible(False)> Public Delegate Sub PrintEventHandler()
<ComVisible(False)> Public Delegate Sub SavedEventHandler()

<GuidAttribute("93D44286-4BA4-4cc7-8971-0C7831EA0354"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _Form
<DispId(&H1001)> Sub ShowForm(ByVal sCN As String, ByVal sGUID As
String)
<DispId(&H1002)> Sub ShutDownForm(ByVal SaveOptions As UInt32)
<DispId(&H1003)> Sub DoVerb(ByVal Verb As Int32)
End Interface

<GuidAttribute("06670E52-A3C2-480b-8D7A-7CE3DD1D03A3"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _FormEvents
<DispId(&HF001)> Sub NewMessage()
<DispId(&HF002)> Sub Shutdown()
<DispId(&HF003)> Sub Print(ByVal PageNumber As UInt32, ByVal Status As
UInt32)
<DispId(&HF004)> Sub Saved()
End Interface

' This is your COM object, you must implement _Form and _FormEvents
' For each object that you create you will need to assign a unique GUID
' and give the class a unique ProgID
<GuidAttribute("9d8a13bf-df52-3084-954b-95e85887111d"),
ProgIdAttribute("SQLView.Form"), ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(GetType(_FormEvents))> _
Public Class MAPIForm
Implements _Form

Public Event NewMessage As NewMessageEventHandler
Public Event ShutDown As ShutdownEventHandler
Public Event Print As PrintEventHandler
Public Event Saved As SavedEventHandler

Private WithEvents frm As New OutlookForm

' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub

Public Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
Implements _Form.ShowForm
' This is called by Outlook when a form needs to be displayed
frm.txtCON.Text = sCN
frm.txtGUID.Text = sGUID
frm.Show()
End Sub

Public Sub ShutDownForm(ByVal SaveOptions As UInt32) Implements
_Form.ShutDownForm
' The is called by Outlook when it wants to close the form
End Sub

Public Sub DoVerb(ByVal Verb As Int32) Implements _Form.DoVerb
' The is called by Outlook when a verb (eg Print) needs to be done
' Verbs are defined in the cfg file
End Sub

Private Sub frm_ShutDownForm() Handles frm.ShutDownForm
RaiseEvent ShutDown()
End Sub
End Class
-----------------------------

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com

Nov 21 '05 #1
3 1571
more code is needed... it's hard to help you when you're not posting
enough code to allow a respondent to test it and get the same error. I
do realize that this is part of a commercial project, but if you want
to get help in a public forum, you'll have to divulge more -- your
previous problem that was looking at the wrong typelib being a
case-in-point (with sufficient code, someone else likely would have
found it quickly)

as an aside, why are jumping back and forth between technologies? it
would seem simpler to roll forward the parts of your app that call
legacy COM components than to write new components and force old apps
to use them...

Nov 21 '05 #2
Hmm, not sure what else I can produce in terms of code - aside from the
actual COM client.

I don't think I am jumping back and forth ...

Legacy application is written in C++ and is COM compliant and needs to talk
to a .NET component - how they talk to each other, COM, is what is being
developed.

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
more code is needed... it's hard to help you when you're not posting
enough code to allow a respondent to test it and get the same error. I
do realize that this is part of a commercial project, but if you want
to get help in a public forum, you'll have to divulge more -- your
previous problem that was looking at the wrong typelib being a
case-in-point (with sufficient code, someone else likely would have
found it quickly)

as an aside, why are jumping back and forth between technologies? it
would seem simpler to roll forward the parts of your app that call
legacy COM components than to write new components and force old apps
to use them...

Nov 21 '05 #3
enough client code to throw into the compiler would be helpful... I
often find my problems more readily when I create test stubs that work
while the original doesn't...

as for the back and forth...
I am wondering if it wouldn't be easier to roll the part that needs to
interact with the COM object forward to .NET. I realize the
(potential) enormity of updating an entire application, but it seems
like rolling the presentation layer forward would be manifestly easier
than shoe-horning a .NET COM component into a legacy application...

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ondrej Sevecek | last post by:
Hello, what is the difference between "event" and the only use of delegate? Why one should note events with "event" keyword when the functionality seems the same as with pure delegates? When I...
6
by: Marty | last post by:
Hi, I would like to have my class to execute eventually an outside function. I was thinking to pass to my class constructor a delegate object that would be later used in my class to be...
4
by: Tedb | last post by:
Is there any reason why you can't reuse a delegate object instance versus creating a new one each time? For example in the following scenario I have a DataPoints object with an array of DataPoint...
0
by: Wavemaker | last post by:
One of the things I've struggled with from time to time is handling events raised on different threads. For example, an object could be listening to events from one or more objects running in...
4
by: ^MisterJingo^ | last post by:
Hi all, I've been trying to get my head around delegates. The book i'm using had a single example, not much explaination, and didn't show how to set up a delegate and pass variables in and out...
7
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it...
7
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the...
3
by: steve | last post by:
Hi all, I want to be able to hirearchally define event delegate (declarations) WITHIN interfaces. Unfortunatelly C# 1 doesn't appear to support it. How does the following look as a...
3
by: lothar.behrens | last post by:
Hi, I am thinking about the delegate mechanism and try to understand it. I am coming from C++ and know about callbacks or member callbacks. In C++ I have this typedef for every class that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.