stewe
asked on
CComObject
Hi !
I receive an IDispatch* in a COM object's method. I know what object should it be.
I would like to acces it's ATL class so I can manipulate it.
Details:
class ATL_NO_VTABLE CMyObj :
public CComObjectRootEx...
...
STDMETHODIMP COtherObj::Manipulate(IDis patch *ptr)
{
CMyObj *obj=???ptr???
obj->m_iY=1;
obj->Manipulate(...);
}
Maybe using CComObject or something like that.
Stewe
I receive an IDispatch* in a COM object's method. I know what object should it be.
I would like to acces it's ATL class so I can manipulate it.
Details:
class ATL_NO_VTABLE CMyObj :
public CComObjectRootEx...
...
STDMETHODIMP COtherObj::Manipulate(IDis
{
CMyObj *obj=???ptr???
obj->m_iY=1;
obj->Manipulate(...);
}
Maybe using CComObject or something like that.
Stewe
Hi!
(Don't really know what migel means - need not to be wrong, though -, but)
I would make it this way:
STDMETHODIMP COtherObj::Manipulate(IDis patch *ptr)
{
IMyObj *obj;
ptr->QueryInterface(IID_IM yObj, (void**)&obj);
obj->m_iY=1;
obj->Manipulate(...);
}
(Don't really know what migel means - need not to be wrong, though -, but)
I would make it this way:
STDMETHODIMP COtherObj::Manipulate(IDis
{
IMyObj *obj;
ptr->QueryInterface(IID_IM
obj->m_iY=1;
obj->Manipulate(...);
}
ASKER
This is the way that I'm using now.
But. m_iY is not a COM property but a C++ class property.
So I need
class MyObj*
not
IMyObj *
Is it possible ?
>>>> So I need class MyObj* not IMyObj * Is it possible ?
No, it's not (that's what miguel wanted to say).
The design of COM limits you to using the interface, since you don't know for sure what "hides behind" the IMyObj*. In fact, you could even get it working undercertain conditions, but I could break it with one additional registry entry.
No, it's not (that's what miguel wanted to say).
The design of COM limits you to using the interface, since you don't know for sure what "hides behind" the IMyObj*. In fact, you could even get it working undercertain conditions, but I could break it with one additional registry entry.
Thank you peter! my English not so guud :-)
ASKER
What do you mean 'I could break it with one additional registry entry' ?
HI!
By this phrase, Peter mean that any user can implement your interface and pass such object to you. So unpredictable result can occure.
By this phrase, Peter mean that any user can implement your interface and pass such object to you. So unpredictable result can occure.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yea. I do it.
I keep CMyObj in-touch, f.e. mapped, and look up with a string property as key. So I use that IDispatch (IMyObj) to get the key value, then look up.
and... it works.
Thx
I keep CMyObj in-touch, f.e. mapped, and look up with a string property as key. So I use that IDispatch (IMyObj) to get the key value, then look up.
and... it works.
Thx
>> I keep CMyObj in-touch, f.e. mapped, and look up with a string property as key.
perfect!
perfect!
You can`t directly cast IDispatch pointer to the your object since you can receive anything else.
You can add internal interface (not registered in the TLB) to the your class and manupulate it by this interface