how to return a string from COM DLL
C / C++ / MFC
2
Posts
2
Posters
0
Views
1
Watching
-
I 've one function that 's written with COM DLL. I want to return a string from that function. function declaration is like that STDMETHODIMP CMyClass::Command() from that function how can I return a string. thanks in advance.
-
I 've one function that 's written with COM DLL. I want to return a string from that function. function declaration is like that STDMETHODIMP CMyClass::Command() from that function how can I return a string. thanks in advance.
In the .IDL (or ODL file) change the declaration so it looks something like this:
HRESULT Command([out, retval] BSTR *pOut);
Now the function should look like this:
STDMETHODIMP CMyClass::Command(BSTR *pOut) { if ( pOut == NULL ) { return E_POINTER; } *pOut = SysAllocString(L"Your string here!"); return S_OK; }
If you're not familiar with
BSTR
s you should read up on them. Steve