473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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. CompilerService s;
using System.Reflecti on;
using System.Diagnost ics;

// Outgoing events
[InterfaceType(C omInterfaceType .InterfaceIsIDi spatch)]
public interface IEvents
{
void OnMyEvent(int MyCode);

}

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

public delegate void MyDelegate(int nCode);

// Notify class
[ComSourceInterf aces("IEvents")]
[ClassInterface( ClassInterfaceT ype.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_Cod e);
}
}
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(__uuido f(ClassLibrary1 ::Notify))

Any suggestions would be appreciated.
Thanks!

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

// Notify class
[ComSourceInterf aces("IEvents")]
[ClassInterface( ClassInterfaceT ype.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 IConnectionPoin tContainer
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 InterfaceIsIDis patch (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
1294
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 unmanaged C++ class "B" has a member variable of type "A". Can class "B" directly receive the events of class "A", and if so how (code examples)? What I mean by "directly" is can one write code like: m_ManagedObject->EventOccurred += gcnew...
0
3624
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 Subject or Message Body for the e-mail that triggers the Event Sink to run. What am I doing wrong? Thank you,
0
1195
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 mising link. I am getting this code: error C3731: incompatible event 'void sLib::CDataset::OnSetProgress(sLib::CProgressInfo &)' and handler 'void SkyscanLibBase::CDataset::DoLocalProgress(sLib::CProgressInfo &)'; event source and event handler...
1
1939
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 handler in the unmanaged class because the types are managed (compiler error C3265). For example, I can't declare the following sink: static void Row_Deleting(Object* sender, System::Data::DataRowChangeEventArgs* e)
0
1930
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 these DLL interoperate with managed code. Among others things, the managed code need to be able to register for notification with the boost signals. I've tried different approaches (trying to register a pinned delegate with the boost::signal, etc...),
13
2248
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 code for the listener that launches the listener thread. Managed ----------
1
3500
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 products events which I want to consume (sink) within Internet Explorer. I'm following the instructions at: ms-http://support.microsoft.com/default.aspx?kbid=313891.
6
1592
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 create and connect and call the method in the C# Class Lib w/o problems. However, I am having a hard time sinking the C# events in my managed C++ app. I am using .NET 1.1. Note that I can do this through COM Interop; however, I am would prefer
7
5131
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 it's the 64-bit version of Exchange 2007 installed on Windows Server 2003 Enterprise x64, while the Exchange 2007 SDK samples seem mostly geared toward 32-bit. Even at that, I was able to build the TLB and install it into COM+ Component Services,...
0
7955
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7883
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8379
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8019
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3873
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1223
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.