Pergunta

I know COM is old now, but every now and then we have to do some work on it. I was working on an ATL COM application in Visual Studio, I tried to add a method to an Interface, but it won't let me change the return type from HRESULT to something else like long or BSTR.

I can't recall exactly how it was done, may be through some out parameters. Can someone tell me how we do return types in COM Interface Methods ?

Foi útil?

Solução

Return type in COM is always HRESULT (except special methods AddRef and Release), so you need to use out parameter:

HRESULT GetString([out] BSTR* val);

Also you can add retval attribute to turn the output parameter into the return value for script languages (that uses IDispatch):

HRESULT GetString([out, retval] BSTR* val);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top