473,320 Members | 2,083 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,320 software developers and data experts.

connectionpoint in C#

Hi all,
I want to write a C# server that will invoke all umanaged COM client
methods; using something like connecitonpoint mechanism in C++.
Does anybody know how i can do this in C#?

tia,
Sandip Shahane
Nov 16 '05 #1
3 5764
I have seen many articles on how to "use .NET managed event sinks to catch
event notifications sent from COM objects"
but i am looking for the converse of this i.e.:
How to "write COM sinks to catch event notifications sent from .NET
source"?

Thanks,
Sandip

"sandip" <ss******@bindview.com> wrote in message
news:Ot***************@TK2MSFTNGP11.phx.gbl...
Hi all,
I want to write a C# server that will invoke all umanaged COM client
methods; using something like connecitonpoint mechanism in C++.
Does anybody know how i can do this in C#?

tia,
Sandip Shahane

Nov 16 '05 #2
Here is some code I have recently used in C# for the DWebBrowserEvents2 COM
interface.

Hope it helps, Adam

public class IEEvents : DWebBrowserEvents2
{
private int cookie = -1;
private UCOMIConnectionPoint icp;
private InternetExplorer m_IEClass;

public IEEvents(ref InternetExplorer IEClass)
{

//Call QueryInterface for IConnectionPointContainer
m_IEClass = IEClass;
UCOMIConnectionPointContainer icpc =
(UCOMIConnectionPointContainer)m_IEClass;
// Find the connection point for the
// DWebBrowserEvents2 source interface
Guid g = typeof(DWebBrowserEvents2).GUID;
icpc.FindConnectionPoint(ref g, out icp);

//Pass a pointer to the host to the connection point
icp.Advise(this, out cookie);
}

~IEEvents()
{
if (cookie != -1)
{
icp.Unadvise(cookie);
}
cookie = -1;
}

//Events Go Here
}

"sandip" <ss******@bindview.com> wrote in message
news:Ot***************@TK2MSFTNGP11.phx.gbl...
Hi all,
I want to write a C# server that will invoke all umanaged COM client
methods; using something like connecitonpoint mechanism in C++.
Does anybody know how i can do this in C#?

tia,
Sandip Shahane

Nov 16 '05 #3
Actually I want to implement COM sink in C++ for C# server.
I am trying to implement event sink in C++ client, but it gives me member
not found error when call comes back from C# event raised.

Here are both C# source(taken from MSDN article: "Raising Events Handled by
a COM Sink") and C++ sink:
"VB client for the same C# source it is working fine"

//********** C# source ***************
using System;
using System.Runtime.InteropServices;
namespace EventSource
{
public delegate void ClickDelegate(int x, int y);
public delegate void ResizeDelegate();
public delegate void PulseDelegate();

// Step 1: Defines an event sink interface (ButtonEvents) to be
// implemented by the COM sink.
[GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967") ]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface ButtonEvents
{
void Click(int x, int y);
void Resize();
void Pulse();
}
// Step 2: Connects the event sink interface to a class
// by passing the namespace and event sink interface
// ("EventSource.ButtonEvents, EventSrc").
[ComSourceInterfaces(GetType(ButtonEvents))]
public class Button
{
public event ClickDelegate Click;
public event ResizeDelegate Resize;
public event PulseDelegate Pulse;

public Button()
{
}
public void CauseClickEvent(int x, int y)
{
Click(x, y);
}
public void CauseResizeEvent()
{
Resize();
}
public void CausePulse()
{
Pulse();
}
}
}

following statement in the attached client gives error "Member not found",
don't know what is going wrong.
hr = pButton->CauseClickEvent(x,x);

Any idea?

Thanks,

Sandip

"Adam Stirk" <.> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Here is some code I have recently used in C# for the DWebBrowserEvents2 COM interface.

Hope it helps, Adam

public class IEEvents : DWebBrowserEvents2
{
private int cookie = -1;
private UCOMIConnectionPoint icp;
private InternetExplorer m_IEClass;

public IEEvents(ref InternetExplorer IEClass)
{

//Call QueryInterface for IConnectionPointContainer
m_IEClass = IEClass;
UCOMIConnectionPointContainer icpc =
(UCOMIConnectionPointContainer)m_IEClass;
// Find the connection point for the
// DWebBrowserEvents2 source interface
Guid g = typeof(DWebBrowserEvents2).GUID;
icpc.FindConnectionPoint(ref g, out icp);

//Pass a pointer to the host to the connection point
icp.Advise(this, out cookie);
}

~IEEvents()
{
if (cookie != -1)
{
icp.Unadvise(cookie);
}
cookie = -1;
}

//Events Go Here
}

"sandip" <ss******@bindview.com> wrote in message
news:Ot***************@TK2MSFTNGP11.phx.gbl...
Hi all,
I want to write a C# server that will invoke all umanaged COM client
methods; using something like connecitonpoint mechanism in C++.
Does anybody know how i can do this in C#?

tia,
Sandip Shahane




Nov 16 '05 #4

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

Similar topics

2
by: Jeff Van Epps | last post by:
We've been unable to get events working going from C# to VJ++. We think that the C# component is being exposed properly as a ConnectionPoint, and the Advise() from the VJ++ side seems to be...
5
by: Morten Overgaard | last post by:
Hi I have a C# component which fires events. I want to catch these events in my MFC app compiled with the /clr. I know I can define a managed class in my MFC app which traps the events - but I...
9
by: wdwedw | last post by:
I have included all the source codes in the attached MyTest.zip (http://www.codeguru.com/forum/attachment.php?attachmentid=11218) There are three projects: VBTestCOM project is a apartment...
20
by: Frank Rizzo | last post by:
I have a class that handles events from another class. Unfortunately these events arrive on a different thread. How can I marshal the code execution to the thread on which the caller class was...
4
by: igd | last post by:
I am forced to decorate my .NET Main()-method with , since an unmanaged function (which i am calling through P/Invoke) calls CoCreateInstance() in turn. The problem is, that another unmanaged...
2
by: joblst | last post by:
Hello. I have a trouble. My prog connects to the IEs with ConnectionPoint - DWebBrowserEvent2 - Advise. After some time it must unadvise from IE if it executed. Using IShellWindows interface I...
2
by: sugee | last post by:
Hi, am trying to implement connectionpoint in my appln. where in i try calling a method in my server. this throws an error An unhandled exception of type 'System.Runtime.InteropServices.COMException'...
28
by: | last post by:
I have a multi threaded windows form application that runs great after calling Application.Run(). Application.Run is required for a COM component I a using in the app (required for message loop). ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.