none
sinking com events in vb.net - multiple events RRS feed

  • Question

  • This one is really driving me crazy.  I am developing a vb.net app that also includes a COM object.  The COM object exposes an dual automation interface along with a dispinteface containing 3 events.  The object also supports the 4 connection point interfaces.  I build the COM class and from the ocx, build an assembly which is referenced by the vb.net app.  In the vb.net app, I create the control using  m_obj = New MyComClass.  Using m_obj, I can access the COM obj using the automation interface without any problem.  Now I want to sink the events raised by the COM object.  If I add the code AddHandler m_obj.OnThis, AddressOf OnThisHandler, everything works fine,  If instead I add AddHander m_obj.OnThat, AddressOf OnThatHandler, it also works.  The trouble comes if I try to add both( or more generally multiple) handlers at the same time.  It no longer works. 

     

    I don't understand this well enough to see all the implications of this but I have discovered that the immediate problem is that each call to AddHandler generates a call to ConnectionPoint.Advise.  The input arg pUnk is different for each or these calls and further when Advise calls punk->QueryInterface (DIID_IMyEvents...  the pdispEvents pointer returned is different!!!  So what happens is that using the first pdispEvents, I can raise the which ever of the events is defined by the first call to AddHandler. If I use the value returned as a result of the second call to AddHander I can raise that event and so on.  The problem with all this is the that COM object has no way of knowing which pdispEvent corresponds to which event.  With multiple events(more than 2) I can see that returned pointers are not in vtable order so soring by value won't work.  Why is the runtime sending back multiple pointers to what should be a single object?  Is there some way to set up the handers in the vb.net app that won't result in mulitple pdispEvent pointers being generated?

    Wednesday, March 5, 2008 11:09 PM

All replies

  • To troubleshoot this issue, we really need the source code and the detailed repro steps to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.


    You can send a sample project and repro steps in details to my email address which can be found in my personal profile page.

    Thursday, March 6, 2008 10:56 AM
  • Thanks for the reply.  I have sent a zip file to your email address containing the COM control project and a vb file to create the control.

     

     

    Thursday, March 6, 2008 5:47 PM
  • Could you please clarify the "LJDesignsLib.LJControlBase" in your VB.net code file?
    Friday, March 7, 2008 6:46 AM
  • I have send two simplified replacment files to your email address.  I see that this question has a lot of hits so there seems to be interest in finding a resolution to this problem. 

    Friday, March 7, 2008 4:57 PM