473,386 Members | 1,733 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,386 software developers and data experts.

Managed event, unmanaged sink

I have created a .NET component in C# that has 2 interfaces. One is an
incoming interface with methods being exposed to COM-aware clients. The
other is an outgoing event interface that the unmanaged C++ sink
implements. Here is the C# code:

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Diagnostics;

// Outgoing events
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface IEvents
{
void OnMyEvent(int MyCode);

}

// Incoming methods
public interface INotify
{
int Code { get; set; }
}

public delegate void MyDelegate(int nCode);

// Notify class
[ComSourceInterfaces("IEvents")]
[ClassInterface(ClassInterfaceType.None)]
public class Notify : INotify
{
private int m_Code = 5;

public event MyDelegate OnMyEvent;

public Notify()
{
}

public int Code
{
get { return m_Code; }
set
{
m_Code = value;
if (value >= 10)
{
try
{
if (null != OnMyEvent)
{
OnMyEvent(m_Code);
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}

}
}
}
}

In my unmanaged C++ client, I can access the INotify interface just
fine. But I want to access the event interface too. How do I do that?

Currently, I define the C++ pointer as:
ClassLibrary1::INotifyPtr pNotify;

And then my C++ class constructor's initializer has:
pNotify(__uuidof(ClassLibrary1::Notify))

Any suggestions would be appreciated.
Thanks!

Dec 13 '05 #1
1 1955
<ML****@hotmail.com> wrote
public delegate void MyDelegate(int nCode);

// Notify class
[ComSourceInterfaces("IEvents")]
[ClassInterface(ClassInterfaceType.None)]
public class Notify : INotify [...]
In my unmanaged C++ client, I can access the INotify interface just
fine. But I want to access the event interface too. How do I do that?

I've never done that. But typically, events are implemented with
connection points. You QI for the IConnectionPointContainer
and find the connection point for the event interface. You
can establish a connection to your implementation of the event
interface via Advise.

However, implementing dispinterfaces is a bit of a pain in
VC++. Unless you have any hard reason to do so, you
should not us InterfaceIsIDispatch (if you really want
late-binding you can still use a dual interface).

Anyway, you might want to use ATL to implement the
interface. See AtlAdvise and BEGIN_SINK_MAP.

-hg
Dec 13 '05 #2

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

Similar topics

0
by: Mario Giacomino | last post by:
Hi, I am using .NET Framework 2.0 with Visual Studio 2005 Beta Professional. Here is the deal: Currently I have a managed class "A" (located ina C# class library) that has a few custom events. An...
0
by: Notlwonk | last post by:
I have written an event sink in C# that hooks into our Exchange Server 2000 store. The sink fires and the various LOG files are created, but for some reason I cannot seem to read-in the e-mail...
0
by: | last post by:
I am trying to use my unmanaged c++ class library in managed classes. So far everything seems to be ok, just passing on the __events from unmanaged to managed code using the __hook functions is a...
1
by: Bob Whiton | last post by:
I have an unmanaged class which has a member variable: gcroot<DataTable*> myDataTable; I would like to sink the RowDeleting event in my UNmanaged class. However, I can't declare an event...
0
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have...
13
by: DD | last post by:
I'm puzzled how to mix managed/unmanaged C++ in the following scenario: Unmanaged ------------ Callback listener class with method that should call an event in managed Form1. Initialization...
1
by: Apu Nahasapeemapetilon | last post by:
Hello and thank you in advance for your help. Can anyone think of a reason why this code would work properly on one PC, but not another? I've got a System.Windows.Forms.UserControl that...
6
by: fshawish | last post by:
Hello all, I have a C# Class Lib that exposes a public events, methods and properties. I am referencing this ClassLib from an MFC DIalog app that is compiled with /CLR. I use gcroot<T> to...
7
by: Don | last post by:
Getting errors after following the MSDN article on using VB.NET (and VS2005) for "Implementing a Managed OnSave Event Sink" for Exchange Server 2007. Not sure, but part of the problem may be that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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,...

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.