In C++ Builder XE7, I created a simple COM automation object:
So, the wizard created declarations/implementations for get/set methods:
interface IMyObject: IDispatch
{
[propget, id(0x000000CA)]
HRESULT _stdcall MyProperty([out, retval] long* Value);
[propput, id(0x000000CA)]
HRESULT _stdcall MyProperty([in] long Value);
};
STDMETHODIMP TMyObjectImpl::get_MyProperty(long* Value)
{
try
{
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IMyObject);
}
return S_OK;
}
// ---------------------------------------------------------------------------
...
In order to get the property value for automation clients, I inserted the code to assign the Property value to the Value referenced by the parameter:
STDMETHODIMP TMyObjectImpl::get_MyProperty(long* Value)
{
try
{
*Value = MyProperty;
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IMyObject);
}
return S_OK;
}
Getting the property value in the client application, the server function TMyObjectImpl::get_MyProperty(long* Value) seems to run recursively until gets stack overflow.
Here is a simple client code:
Variant Object;
double N;
V = Variant::CreateObject("MyProject.MyObject");
N = V.OlePropertyGet("MyProperty");
What I am doing wrong in this assignment?
*Value = MyProperty;
STDMETHODIMP TMyObjectImpl::get_MyProperty(long* Value)
{
try
{
*Value = MyProperty;
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IMyObject);
}
return S_OK;
}
Reading MyProperty
is implemented by a call to get_MyProperty
. Hence the unterminated recursion.
You need to implement get_MyProperty
by returning a value obtained by some other means. For instance, you might return a constant value:
*Value = 42;
Or you might return a value stored in a member field:
*Value = myPropertyValue;
where myPropertyValue
is a member field of your class.
User contributions licensed under CC BY-SA 3.0