Solved

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

Posted on 2008-06-19
7
728 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

680 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