Solved

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

Posted on 2008-06-19
7
740 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

624 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