473,568 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
IConnectionPoin tContainer which seems to work.

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

System.NullRefe renceException: Object reference not set to an instance of an
object.
at MapiForm._FormE vents.Shutdown( )
at MapiForm.MAPIFo rm.frm_ShutDown Form() in D:\My
Documents\SQLVi ew\Forms\MAPIFo rm\MAPIForm.vb: line 63
at MapiForm.Outloo kForm.txtShutdo wn_Click(Object sender, EventArgs e) in
D:\My Documents\SQLVi ew\Forms\MAPIFo rm\OutlookForm. vb:line 113
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr 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(Fal se)> Public Delegate Sub NewMessageEvent Handler()
<ComVisible(Fal se)> Public Delegate Sub ShutdownEventHa ndler()
<ComVisible(Fal se)> Public Delegate Sub PrintEventHandl er()
<ComVisible(Fal se)> Public Delegate Sub SavedEventHandl er()

<GuidAttribute( "93D44286-4BA4-4cc7-8971-0C7831EA0354"),
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsDual)> _
Public Interface _Form
<DispId(&H1001) > Sub ShowForm(ByVal sCN As String, ByVal sGUID As
String)
<DispId(&H1002) > Sub ShutDownForm(By Val SaveOptions As UInt32)
<DispId(&H1003) > Sub DoVerb(ByVal Verb As Int32)
End Interface

<GuidAttribute( "06670E52-A3C2-480b-8D7A-7CE3DD1D03A3"),
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsDual)> _
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( ClassInterfaceT ype.None),
ComSourceInterf aces(GetType(_F ormEvents))> _
Public Class MAPIForm
Implements _Form

Public Event NewMessage As NewMessageEvent Handler
Public Event ShutDown As ShutdownEventHa ndler
Public Event Print As PrintEventHandl er
Public Event Saved As SavedEventHandl er

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.Tex t = sGUID
frm.Show()
End Sub

Public Sub ShutDownForm(By Val SaveOptions As UInt32) Implements
_Form.ShutDownF orm
' 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_ShutDownFor m() Handles frm.ShutDownFor m
RaiseEvent ShutDown()
End Sub
End Class
-----------------------------

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

Nov 21 '05 #1
3 1582
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__sur e" <st*********@ho tmail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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
4814
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 call some delegate, in which thread this delegate gets called - callers = synchronous, or some other thread = asynchronous? And in what thread is...
6
7736
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 triggered. Does a delegate is the correct object to use to do that? Thanks!
4
3136
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 objects, each of these has a Changed event. My Client objects subscribe to some or all of the DataPoint Changed events. Client1 creates a new...
0
2486
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 different threads besides itself. There is a concern for thread safety. There are various ways of dealing with this. One way is to make the class thread...
4
2003
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 of the functions it refers to. So I've been playing around and came up with he following code. I know it doesn't do much, but I just wanted to fit...
7
1769
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 the piece of code which doesn't appear here, but abstracts the btnAccept_Click method?
7
3435
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 eventing code is slightly hidden. when you use events in Vb.Net you type this: <code> Public event MyEvent() </code>
3
11546
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 work-around? Are there better ways of doing this?
3
1394
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 implements member callbacks: typedef bool (__cdecl IEventHandler::*lbEvHandler)(IUnknown* uk);
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.