Re: Doubts on mixed threading (FTM -Both ) objects
Thanks Brian ,
I am novice in this area and trying to understand the concepts ..
Kindly please correct if I am wrong .
1) a COM Object can be obtained from (I am not sure the usage of term
"COM Object" here is correct or not )
a)CComObject<CoClass>::CreateInstance()
-only if we have CoClass implementation source
-we will be getting the CoClass object pointer
If we have 2 Objects of CoClass1 and CoClass2 implemented Interface1
and Interface2
If both are created in the same process and apartment , Is that legal
to implement communications between these classes using member
functions(member of the class but not defined by Interface1 or
interface 2) ?
b) CoCreateInstance
In this case a class will be created and I 'll be getting the requested
interface pointer(pInter) .
Can I cast pInter to CoClass pointer ?
CoClass *pCoClass = CoClass <Some_Cast>pInter;
pCoClass->MemberFunction ()
c) direct pointer from some function
cannot perform any casting, it may be a fully qualified object or it
could be implemented by some other coclass or it could be a proxy to an
object created somewhere
2) we have this class registered as -BOTH in registry
CoClass::Interface1
{
CoClass::InterfaceMethod1()
{
CreateThread(this); //???
}
CoClass::Function()
{
}
CoClass::InterfaceMethod2()
{
}
Member Variable m_Var;
}
static MyThread(void *p)
{
HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoClass *pCoClass= (CoClass*) p;
p->Function(); // {call 1} ?
p->InterfaceMethod2(); // {call 2} ?
p->m_Var; //{call 3} ?
}
where 'Function()' is just a member function which is not the part of
any interface .
and 'InterfaceMethod1 & InterfaceMethod2' is defined in 'Interface1'
For example when a client create the above object on a single thread
apartment
CoInitialize()
Interface1 *pInter =CoCreateInstance(CLSID_CoClass, IID_Interface1)
pInter->InterfaceMethod1();
CoUnInitialize()
In the above scenario {call 1} and {call 2} becomes illegal ... right
?
To resolve this we could pass a marshaled pointer and legally perform
{call 2} , But there might be situations where we need to perform
something like {call 1} and {call3}
(which are not the part of interface)
how could we resolve it ?
3)
When we talked about marshalling ..Interface can be marshalled using
GIT etc ..how can I marshal a CoClass object pointer ?
CoClass::InterfaceMethod1()
{
LPVOID pContext=MARSHALL (this); // How????
CreateThread(pContext);
}
Thanks