Discussion Locked

Return values for ATL Component.

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

How to set the return value for a ATL component developed through VC++. Please be me a solution with example.

Thanks in advance.

Manohar

1 reply

by andrew

What kind of return value ([out retaval], HRESULT)? To what kind of caller (VB, internal)?

ATL COM methods return an HRESULT, and return data in parameters passed by reference (pointers). The IDL indicates which direction the paramters are going.To make it appear that the method is returning a single data value, use the [out retval] attribute.

Here's an example of returning a string value to a VB caller:

STDMETHODIMP CDSNManager::GetDSN(BSTR Application, BSTR *ConnectionString)
{
CComBSTR Provider = "Provider=SQLOLEDB.1";
*ConnectionString = Provider.Detach();

return S_OK;
}

here's the IDL:

[id(1), helpstring("test")] HRESULT GetDSN([in] BSTR Application, [out, retval] BSTR* ConnectionString);

Hope this is what you were looking for.

This discussion is closed to new replies.