Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-19
7
Medium Priority
?
747 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decadeā€¦

730 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