Solved

ATL COM connection point from worker thread not working with .NET client

Posted on 2008-06-19
7
710 Views
Last Modified: 2013-12-05
In the past I have written ATL COM dlls with visual studio 6 using connection points to communicate with VB6 clients.  The dll has a worker thread that fires the connection point back to the Windows XP VB6 client app.  When I port this to VS2005 and the client is now .NET on the CE 5.0 platform the connection point does not fire in the client app.

I know the connection point works because I have fired it from the dll and the client gets it.  But when the worker thread does it the client does not see it.  Any idea as to what the difference could be that is making this fail?

thanks.
 
0
Comment
Question by:tkamrath
  • 4
7 Comments
 
LVL 5

Expert Comment

by:JuckMan
ID: 21833484
Connection points are created for the ATL/COM world. When you port this to .NET can you convert this to an event pub/sub model. This is easy to code and maintain.

Also I am not clear on when it work and when it fails. Could you eloborate on your following statement..

"I know the connection point works because I have fired it from the dll and the client gets it.  But when the worker thread does it the client does not see it. "


0
 

Author Comment

by:tkamrath
ID: 21833954
I have implemented the event object on the .NET side and added the pointer to the object connection point table.  here is the code that does this.

        public atlcomCELib.testerClass mytest;

        // this class is required to create the COM event handler routines
        // in such a way that they can be registered with the ATL COM dll.
        public class ManagedSink : _ItesterEvents
        {
            public Form1 Parent;

            public void OnTestOneDone(int status)
            {
                int y;
                float z;
                y = status;
                z = Parent.mytest.outp;
            }
        };

       
        private void Form1_Load(object sender, EventArgs e)
        {
            ManagedSink ms = new ManagedSink();
            ms.Parent = this;
            mytest = new atlcomCELib.testerClass();

            // this registers the handler routine with the ATL COM dll.
            // so when an event is fired from the dll this handler routine is run.
            mytest.OnTestOneDone += ms.OnTestOneDone;

            mytest.testOne(12345);
        }

When I fire the event from the ATL COM object via the mytest.testOne method it works fine.  But when the worker thread that the object creates fires the event it does not work.  And as I said, this architecture works in windows XP with VB6 as the client.  The worker thread code  is as follows :

void Ctester::FireDoneEvent()
{
      Fire_OnTestOneDone (2);
}

DWORD WINAPI Ctester::ThreadRoutine (LPVOID data)
{
   // put the thread into a MTA so that it does not block the main thread.
   CoInitializeEx (NULL, COINIT_MULTITHREADED);
   
   // get a pointer to the Modbus wrapper class for access to data.
   Ctester *me = (Ctester *)data;

   me->FireDoneEvent ();

   // release the thread from the MTA thread pool.
   CoUninitialize();

   return 0;
}

0
 

Author Comment

by:tkamrath
ID: 21854943
I have discovered an additional symptom.

When I step through the proxy routine that looks up the client handler routine in the table I get a failure on the pConnection->Invoke call.  The error is -2147352567 or 80020009.  Again, this only happens when the proxy is called from the worker thread via a method in the object.

worker thread calls object method which then calls the proxy function.  The object is registered for the FREE threading model.  So I believe that the worker thread and the object are in the MTA.
0
 

Author Comment

by:tkamrath
ID: 21866109
More input on this problem.

I built a .NET client to run on the PC with the VS 6.0 version of the ATL COM dll.  It works.

So, my dll works on the PC with a VB6 or a .NET client.

I now only see two variables to this problem.
1)  built with new version of tool, VS2005.
2)  Running on CE platform, which may mean that the ATL is limited or buggy or...

My guess is it is ATL in CE.  Any ideas?
thanks.
0
 

Accepted Solution

by:
tkamrath earned 0 total points
ID: 22034953
You can close this one.  I have gone to MS about this.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now