-
November 28th, 2013, 09:17 AM
#1
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.
-
November 28th, 2013, 09:25 AM
#2
Re: return string from COM method
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?
Victor Nijegorodov
-
November 28th, 2013, 09:32 AM
#3
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
-
November 28th, 2013, 09:41 AM
#4
Re: return string from COM method
i found the problem, its because of
::SysFreeString(str);
what is the correct way to do it?
-
November 28th, 2013, 09:43 AM
#5
Re: return string from COM method
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.
Victor Nijegorodov
-
November 28th, 2013, 12:30 PM
#6
Re: return string from COM method
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?
-
November 29th, 2013, 01:24 AM
#7
Re: return string from COM method
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.
Best regards,
Igor
-
November 29th, 2013, 02:14 AM
#8
Re: return string from COM method
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?
-
November 29th, 2013, 06:00 AM
#9
Re: return string from COM method
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|