Making things pretty by returning BSTR's (ATLCOM)
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
If I understand what your asking STDMETHODIMP Foo([out,retval] BSTR return_string, [out]BSTR out_string) would get you BSTR Foo(BSTR instring) BTW, nice sucking up;)
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
Hi, Actually you can use any data type "Automation Data Types are recomended" to be a return type of any interface's method. But, it's just a recommendation that you use the HRESULT (STDMETHOD macro) as a return type, this return type will give the COM Runtime Environment the ability to return error codes when your component cannot be accessed for any reason. If you don't provide HRESULT as a return type, the COM Runtime Environment cannot return error codes for you. "If You Know That Your Component Will Live With Its Client On The Same Machine, You Can Ignore HRESULT" Regards, ShadiK.
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
>..and have it returned in a variable in the Implementation. (duh) >But can we get this a function in an object to look like: >/////////////// >BSTR Foo(BSTR instring); >/////////////// No, COM interfaces can't return a value like you suggest. The correct (and only way) is as you described,
STDMETHODIMP Foo([out,retval] BSTR* outstring)
Your VB code would then look like, Dim sTemp sTemp = Object.Foo Hope this helps, Michael :-)
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
The solution is simple. In your source file (.cpp) change your function header to this: STDMETHODIMP_(BSTR) YourClass::Foo(BSTR instring) and do the same for your (.h) file. You need to change the entry in the IDL file as well,like the following: BSTR Foo(BSTR instring);:) :) Rookie Programmer
-
We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-
STDMETHODIMP Foo([in]BSTR in_string, [out,retval] BSTR *return_string ) would get you String Foo(String instring) in VB or ASP, In C++ it is HRESULT = YADA.Invoke(dispID, params, vResult,...) Your out_string ends up in the Variant vResult as type vt = VT_BSTR. Use of the retval modifier causes the result to be placed in vResult. Notice the * in BSTR *return_string. Hope this helps, Bill