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

IConnectionPointContainer & C#

Hi all. I'm trying to do something that I think should be fairly
simple. We have some COM objects that used to communicate directly
with each other. I've created a "shim" object in C# that intercepts
all calls from client COM objects and forwards them on to a single
server COM object. The server object, the clients and the shim object
are all in separate processes on the same machine.

The shim object needs to implement all the interfaces the server
object does. I've been able to get all the interfaces working except
IConnectionPointContainer, and it's driving me nuts. I just want to
forward everything, so instead of using delegates I implemented the
raw interface:
public class MyClass: ServicedComponent, /* Other interfaces... */,
IConnectionPointContainer
{
void IConnectionPointContainer.EnumConnectionPoints(out
IEnumConnectionPoints ppEnum)
{
_comServerObject.EnumConnectionPoints(out connectionPoints);
}

void IConnectionPointContainer.FindConnectionPoint(ref Guid riid, out
IConnectionPoint ppCP)
{
_comServerObject.FindConnectionPoint(ref riid, out ppCP);
}
/* Other methods... */
}
This object is a serviced component, creating a COM+ application, but
I'm not sure if that makes any difference.

Anyway, the code seems simple enough, right? Well,
FindConnectionPoint gets called and I can put a breakpoint in the C++
COM code and see that the expected value is getting returned -- we use
the standard IConnectionPointContainerImpl implementation for the
server. And ppCP *seems* to have a valid object in it -- it's not
null at least. But the COM client that gets this IConnectionPoint
object is unable to make calls on it (it generates an access
violation, 0xc0000005).

So I tried putting some test code in the function:

void IConnectionPointContainer.FindConnectionPoint(ref Guid riid, out
IConnectionPoint ppCP)
{
_comServerObject.FindConnectionPoint(ref riid, out ppCP);
Guid guid;
ppCP.GetConnectionInterface(out guid);
}

.... to see if the object was OK in C#. It does not appear to be. I
can again watch what happens in C++ by putting a breakpoint in
GetConnectionInterface. The first thing I notice is that, rather than
calling GetConnectionInterface directly, Advise is called first!
(Advise calls GetConnectionInterface, or I may not have discovered
this). I have no idea why or how Advise is getting called, and its
parameters are corrupt and cause an exception to be thrown back to
C#. I assume that something is getting corrupted between COM and C#,
but I'm not sure what, as I've got plenty of other code that does
similar operations with no problems (nothing with connection points,
though).

So... can anyone give me a hint as to what am I doing wrong here? Is
it possible that things are not getting marshaled properly by the
server's FindConnectionPoint?

Thanks,

Carl

Aug 8 '07 #1
2 4826
It's very possible. In this case, you are doing a hell of a lot of
interface proxy marshalling, and I'm not surprized that something is getting
mucked up along the way. If you really want to use a serviced component
(COM+) and use events as well (which is what connection points are), then I
would recommend using Loosely Coupled Events in COM+, and then having your
shim fire the events, and the clients subscribe to that, if possible.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ca********@yahoo.comwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
Hi all. I'm trying to do something that I think should be fairly
simple. We have some COM objects that used to communicate directly
with each other. I've created a "shim" object in C# that intercepts
all calls from client COM objects and forwards them on to a single
server COM object. The server object, the clients and the shim object
are all in separate processes on the same machine.

The shim object needs to implement all the interfaces the server
object does. I've been able to get all the interfaces working except
IConnectionPointContainer, and it's driving me nuts. I just want to
forward everything, so instead of using delegates I implemented the
raw interface:
public class MyClass: ServicedComponent, /* Other interfaces... */,
IConnectionPointContainer
{
void IConnectionPointContainer.EnumConnectionPoints(out
IEnumConnectionPoints ppEnum)
{
_comServerObject.EnumConnectionPoints(out connectionPoints);
}

void IConnectionPointContainer.FindConnectionPoint(ref Guid riid, out
IConnectionPoint ppCP)
{
_comServerObject.FindConnectionPoint(ref riid, out ppCP);
}
/* Other methods... */
}
This object is a serviced component, creating a COM+ application, but
I'm not sure if that makes any difference.

Anyway, the code seems simple enough, right? Well,
FindConnectionPoint gets called and I can put a breakpoint in the C++
COM code and see that the expected value is getting returned -- we use
the standard IConnectionPointContainerImpl implementation for the
server. And ppCP *seems* to have a valid object in it -- it's not
null at least. But the COM client that gets this IConnectionPoint
object is unable to make calls on it (it generates an access
violation, 0xc0000005).

So I tried putting some test code in the function:

void IConnectionPointContainer.FindConnectionPoint(ref Guid riid, out
IConnectionPoint ppCP)
{
_comServerObject.FindConnectionPoint(ref riid, out ppCP);
Guid guid;
ppCP.GetConnectionInterface(out guid);
}

... to see if the object was OK in C#. It does not appear to be. I
can again watch what happens in C++ by putting a breakpoint in
GetConnectionInterface. The first thing I notice is that, rather than
calling GetConnectionInterface directly, Advise is called first!
(Advise calls GetConnectionInterface, or I may not have discovered
this). I have no idea why or how Advise is getting called, and its
parameters are corrupt and cause an exception to be thrown back to
C#. I assume that something is getting corrupted between COM and C#,
but I'm not sure what, as I've got plenty of other code that does
similar operations with no problems (nothing with connection points,
though).

So... can anyone give me a hint as to what am I doing wrong here? Is
it possible that things are not getting marshaled properly by the
server's FindConnectionPoint?

Thanks,

Carl

Aug 9 '07 #2
Thanks for the response. We want to use COM+ mainly for the role-
based security it provides, but I'm open to other options (although it
may mean re-designing my project.. :-). One of the requirements of my
project is to not change the client code -- clients should be
blissfully unaware that they are now talking to this new COM+
component instead of the old COM object (there's a lot of code that
references this object...).

I haven't read up on LC Events; I had thought that they only worked
with COM+ objects. I'll look into it some more to see if it is a
viable solution for me.

Carl

On Aug 9, 9:41 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
It's very possible. In this case, you are doing a hell of a lot of
interface proxy marshalling, and I'm not surprized that something is getting
mucked up along the way. If you really want to use a serviced component
(COM+) and use events as well (which is what connection points are), then I
would recommend using Loosely Coupled Events in COM+, and then having your
shim fire the events, and the clients subscribe to that, if possible.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Aug 9 '07 #3

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

Similar topics

9
by: Collin VanDyck | last post by:
I have a basic understanding of this, so forgive me if I am overly simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric character...
1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
0
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...

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.