Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

COM object and singleton problem

123 views
Skip to first unread message

d

unread,
Nov 24, 2009, 12:55:01 PM11/24/09
to

hello,

i am working on the COM out of proc server. previously i had designed my COM
server with singleton object but based on the very good response
"http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/83a8de4b-a7a6-46c0-bb40-37f67e5c3c3d"

in MSDN forum i changed it to used same global class. now i would like to
know how could i send events from global class to the COM objects with
connection point.

here is the problem.
i have a class called CGlobalClass g_Globalclass in side the ATL service.
it has a method which takes a long time say init().

i also added a ATL simple Object ( ITestObj ) which impelemnts Connection
points and a method "Fire_Done"
//for simplicity i have removed error checking code.

//COM Method call..
CtestObj::Init()
{
//just call global function
return g_Globalclass.Init();
}

void CGlobalclass::Init()
{
CreateThread(ThreadFun)
return E_PENDING;
}

CGlobalclass::ThreadFun(LPPARAM )
{
//Long processing

//Now how to call CTestObj's connection points function.
}

what i am thinking is like this that when clients would setup the connection
point it would call
Advise/Unadvise. i need to save (those marshalled interface (GDT) )it into a
global class. that i could access into this cGlobalClass.

is my approach correct? does it make sense or you have any other suggestion

--
d

Igor Tandetnik

unread,
Nov 24, 2009, 1:19:14 PM11/24/09
to
d <d...@discussions.microsoft.com> wrote:
> hello,
>
> i am working on the COM out of proc server. previously i had designed
> my COM server with singleton object but based on the very good
> response
> "http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/83a8de4b-a7a6-46c0-bb40-37f67e5c3c3d"
>
> in MSDN forum i changed it to used same global class. now i would
> like to know how could i send events from global class to the COM
> objects with connection point.

Have those COM objects register themselves with the singleton class. The singleton would call some method (not necessarily a COM method, could use a regular C++ method) on COM objects, which in turn would fire an event on their attached event sinks.

> void CGlobalclass::Init()
> {
> CreateThread(ThreadFun)
> return E_PENDING;
> }
>
> CGlobalclass::ThreadFun(LPPARAM )
> {
> //Long processing
>
> //Now how to call CTestObj's connection points function.
> }

For suggestions on firing events from a worker thread, see http://vcfaq.mvps.org/com/1.htm
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925

Brian Muth

unread,
Nov 25, 2009, 1:26:30 PM11/25/09
to
Hi. I posted an answer that fleshes out Igor's response in the original
thread you quoted.

Have you made any progress? Do you have any outstanding questions?

Brian

0 new messages