Problem with Event sink (ATL C++) when the event source is a C# ob

dotnet framework

    Next

  • 1. Invalid cast exception when debugging a VB6 COM addin (SOLVED)
    I found out what the problem was myself. In the VB6 project, Version Compatibility was set to "Project compatibility". This means that each time the project was compiled, new id:s were being generated for each interface. Apparently this is also done each time the project is started in debug mode, even though no visible compilation is done. This meant that the type library I had previously imported with tlbimp and compiled into my C# app was not compatible with the interfaces in use while debugging. Setting Version Compatibility to "Binary compatibility" solved the problem. Magnus Magnus Hyllander wrote: > WPWordXML.Connect conn = (WPWordXML.Connect)addin.Object; > > The line above works fine when I start Word normally. But if I want to > debug the COM add-in, by starting Word from the Visual Studio 6 IDE, > then the cast fails with the following error message: > [...] > So for some reason it seems the the COM object doesn't implement the > WPWordXML.Connect interface when the add-in is running under the VB6 > debugger. > [...] > The strange thing is that I know I have been able to debug like this > before. The C# app was previously developed using VS2003, and for some > time we have now been using VS2005. Could that have anything to do with it?
  • 2. Pointer to array of structs in a struct.
    Heya, I know this has been debated alot, but everywhere I look there is a different solution. So I need some advice on this: The source if the following struct: typedef struct { BYTE Ps; tSTRUCT_NUMERIC * Rates; char * RegNr; char * Cashier; } tFUNC_PARAMS; How should I marshal the " tSTRUCT_NUMERIC * Rates" field? Can/Should I use an IntPtr and in that case, how do I create the array? Cheers, Chris
  • 3. Help with ErrorBar object
    I am stuck. I am trying to automate error bars in an excel chart using office xp interops and C#, but I cannot seem to figure it out. Does anybody have a link to examples or possibly example code? Please...

RE: Problem with Event sink (ATL C++) when the event source is a C# ob

Postby Q3Jpc3RpYW4gTWFyaW5lc2N1 » Fri, 10 Feb 2006 03:39:28 GMT

Sorry, I forgot to mention that I am an MSDN subscriber, so I would
be pleased to see some "Microsoft" answers.

Regards,
Cristian Marinescu






Similar Threads:

1.Problem with Event sink (ATL C++) when the event source is a C# object

Hello everybody,

I need to send from a C# object events, that have to be caught
in my C++ code. I have followed the instructions from the MSDN article
"Raising Events Handled by a COM Sink", but I have a problem
when I call AtlAdvise in the C++ client: the method FindConnectionPoint
will fail with error CONNECT_E_NOCONNECTION (0x80040200).

So I suppose there is a problem with the connetion point map. I found
in another posting that the event instance name has to be the same as the
interface method, which I did, but with no result.

How can I solve my problem? Stupid ideea: is there any way to define 
(correct)
manually the message map for the C# object, like it was possible in C++?

Many thanks for your help,
Cristian





2.ATL Event Sink using C# DLL Event Source

"I/Gear" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM 
> I'm having problems sinking an event in an ATL server using a C# DLL
> as the event source.  I'm using IDispEventSimpleImpl for the
> implmentation and the DispEventAdvise function succeeds.  However, on
> the C# side, I catch the exception "Not Implemented" when the event
> is fired.  I created a simple VB6 client and everything works
> correctly.
>
> BEGIN_SINK_MAP(CEnterpriseManager)
> SINK_ENTRY_INFO(/*nID =*/ 1, DIID_IIGEClient_Events, /*dispid =*/ 0,
> OnDataReceived, &OnDataReceivedFuncInfo)
> SINK_ENTRY_INFO(/*nID =*/ 1, DIID_IIGEClient_Events, /*dispid =*/ 1,
> OnError, &OnErrorFuncInfo )
> END_SINK_MAP()
>
>     dispinterface IIGEClient_Events {
>         properties:
>         methods:
>             [id(0x60020000)]
>             void OnDataReceived(
>                             [in] BSTR RawMessage,
>                             [in] BSTR Message);
>             [id(0x60020001)]
>             void OnError(
>                             [in] BSTR Source,
>                             [in] BSTR Message);
>     };

SINK_ENTRY_INFO uses DISPIDs 0 and 1, whereas the IDL clearly shows
DISPIDs 0x60020000 and 0x60020001. The DISPID in SINK_ENTRY_INFO must
match the actual DISPID in the interface.
-- 
With best wishes,
    Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage


3.ATL Control as an event source and sink

Hi

I am trying to get an ATL single threaded dll to act as both an event source
and sink by using both the  event_source(com),  event_receiver(com, true)
attributes.

Is this even possible?

I am trying to hook my dll to a singleton atl exe that I have created using:

CComPtr<IServer> m_pIServer = 0;
m_pIServer.CoCreateInstance(__uuidof(CServer)); // this works

hr = __hook(_IServerEvents, m_pIServer); //but this returns a negative long.


the exe server has an event HRESULT Transfer(VARIANT data); implimented
under _IServerEvents

I have also created a public function in my dll client called HRESULT 
Transfer(VARIANT data); which should map to the server event but still the 
client wont hook into the server.

Is there any sample code out there.  I am finding it all very hard to find.

Thanks in advance
Steve M







4.Event Handling with VB6 source / C# sink

I am trying to get some event handling implemented in which VB6 COM objects 
raise an event which is caught in .NET code.  The problem is that the VB6 
component is being created through reflection and so I don't know how to 
register the listener (the .NET method) with the source (the VB6 event 
raiser).

One thing that I tried was to create an interface in .NET that gets exported 
through interop.  It looks like this:

    public interface IProgressEventArgs
    {
        int Progress {get; set;}
        int MaxProgress {get; set;}
        string Message {get; set;}
    }

    public class ProgressEventArgs
        : EventArgs, IProgressEventArgs
    {
        private int progress;
        private int maxProgress;
        private string message;
        public ProgressEventArgs () {}
        public ProgressEventArgs
            (int progress, int maxProgress, string message)
        {
            this.progress = progress;
            this.maxProgress = maxProgress;
            this.message = message;
        }
        public int Progress
        {
            get {return progress;}
            set {progress = value;}
        }
        public int MaxProgress
        {
            get {return maxProgress;}
            set {maxProgress = value;}
        }
        public string Message
        {
            get {return message;}
            set {message = value;}
        }
    }

    public delegate void ProgressEventHandler
        (object sender, ProgressEventArgs e);

    public interface IProgressEvent
    {
        event ProgressEventHandler ProgressEvent;
    }

    ...

Now, in the VB6 IDE, after I reference the COM Callable Wrapper for my .NET 
object, when I look at the IProcessEvent object in the Object Browser I see 
two methods, add_ProcessEvent and remove_ProcessEvent, and they both take 
the ProgressEventHandler as an argument.  This looks promising.  But when I 
add the line:

Implements IProgressEvent

in the VB6 code, I get an error messge

      ---------------------------
      Microsoft Visual Basic
      ---------------------------
      Compile error:

      Bad interface for Implements: method has underscore in name
      ---------------------------
      OK   Help
      ---------------------------

So I cannot use the interface because of an underscore in the name???  And 
if I could use this interface, how do I implement the method to add the 
handler to the event's listeners?

Thanks,
Dick 


5.C# Remoted Event Source, COM Event Sink

Hi All,

I'm having trouble figuring this out. I have a C# object, which is
exposed to COM, and fires events. I also have a COM object that can
create the C# object, call DispEventAdvise to be the sink for these
events. This all works fine. Now I want to change it so that instead of
the COM object CoCreating the C# object, I have a C# server which
remotes the object. The COM object uses Activator::GetObject() to get
the remoted object, and then I want to call DispEventAdvise() to set
the COM object as an event sink for the remoted object. I can't get it
to work. DispEventAdvise returns hr = 0x8013150B. I'm assuming that
this should be possible, and help would be greatly appreciated.

My C# object...

using System;
using System.Runtime.InteropServices;

namespace EventSource
{
	public delegate void OnCompleteDelegate();

	// Define event sink interface to be implemented by the COM sink
	[GuidAttribute("7D6A6BB0-C136-4a22-9F84-ABC8603B3D6F") ]
	[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
	public interface IEventTestEvents
	{
		[DispId(0)] void OnComplete();
	}

	[GuidAttribute("88A158C1-896C-467a-B3CC-9F2068093AE2") ]
	[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
	public interface IEventTest
	{
		void FireCompleteEvent();
	}

	// Connects the event sink interface to a class
	[ComSourceInterfaces(typeof(IEventTestEvents))]
	[ClassInterface(ClassInterfaceType.None)]
	public class EventTest : MarshalByRefObject, IEventTest
	{
		// URL information for remoting this object
		public const String RemotingProtocol = "tcp://";
		public const String RemotingPort = "1234";
		public const String RemotingURI = "EventTestUri";
		public const String RemotingLocal = RemotingProtocol + "localhost" +
":" + RemotingPort + "/" + RemotingURI;
		public const String RemotingRemote = RemotingProtocol + "{0}" + ":" +
RemotingPort + "/" + RemotingURI;

		public event OnCompleteDelegate OnComplete;

		public EventTest()
		{
		}

		public void FireCompleteEvent()
		{
			OnComplete();
		}
	}
}


The code in my COM object where I try to call DispEventAdvise...

EventSource::EventTest* et =
static_cast<EventSource::EventTest*>(System::Activator::GetObject(__typeof(EventSource::EventTest),
EventSource::EventTest::RemotingLocal));
	System::IntPtr iUnknown =
System::Runtime::InteropServices::Marshal::GetIUnknownForObject(et);
	IUnknown* pUnk = (IUnknown*)(void*)iUnknown;
	HRESULT hr = DispEventAdvise(pUnk, &DIID_IEventTestEvents);

Thanks for any help,

Tim.

6. Catching C# generated events with an ATL COM Sink

7. problem sinking document mouse events in a C# application

8. C# com and c++ event sink



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 2 guest