return string from COM method
i try to make dll and install it under "Component Services".
i tried to make method that return string but when i test it i don't get any result
Code:
STDMETHODIMP CSimpleChat::CellMe(BSTR name, BSTR** helloMessage)
{
CString temp = _T("Hi ");
temp += name;
temp += ", welcome to the simple chat server!";
BSTR str = temp.AllocSysString();
*helloMessage = &str;
return S_OK;
}
thanks for the help i am new to this.
Re: return string from COM method
Quote:
Originally Posted by
wanttolearn1
i try to make dll and install it under "Component Services".
i tried to make method that return string but when i test it i don't get any result
Code:
STDMETHODIMP CSimpleChat::CellMe(BSTR name, BSTR** helloMessage)
{
...
return S_OK;
}
Are you sure you want BSTR** type for the _out_ parameter, not a BSTR* one?
Re: return string from COM method
i also tried
Code:
STDMETHODIMP CSimplec1::CellOut1(BSTR name1, BSTR* ret)
{
// TODO: Add your implementation code here
CString temp = _T("Hi ");
temp += name1;
temp += ", welcome to the simple chat server!";
BSTR str = temp.AllocSysString();
*ret = str;
::SysFreeString(str);
return S_OK;
}
same problem
Re: return string from COM method
i found the problem, its because of
::SysFreeString(str);
what is the correct way to do it?
Re: return string from COM method
Quote:
Originally Posted by
wanttolearn1
i also tried
Code:
STDMETHODIMP CSimplec1::CellOut1(BSTR name1, BSTR* ret)
{
// TODO: Add your implementation code here
CString temp = _T("Hi ");
temp += name1;
temp += ", welcome to the simple chat server!";
BSTR str = temp.AllocSysString();
*ret = str;
::SysFreeString(str);
return S_OK;
}
same problem
First replacewith
Then remove the ::SysFreeString(str); call because after it is done there is no any data in str.
The ::SysFreeString must be called by the caller of your CellOut1 method.
Re: return string from COM method
Quote:
Originally Posted by
VictorN
The ::SysFreeString must be called by the caller of your CellOut1 method.
how do i do this?
if for example i call the method from vbscript?
i need to call to another method to clear "str" variable?
isn't there a better way?
Re: return string from COM method
Quote:
Originally Posted by
wanttolearn1
how do i do this?
if for example i call the method from vbscript?
i need to call to another method to clear "str" variable?
isn't there a better way?
It's not you to do this. Out value ownership is on client side, so client is responsible for freeing the string. In your case this is vbscript.
PS. You definitely need to get some very basic reading on COM model.
Re: return string from COM method
Quote:
Originally Posted by
Igor Vartanov
It's not you to do this. Out value ownership is on client side, so client is responsible for freeing the string. In your case this is vbscript.
PS. You definitely need to get some very basic reading on COM model.
any recommended articles?
Re: return string from COM method