Why could not display the string?
Hello all:
First I create a component using atl,look:
STDMETHODIMP CTpsz::PrtStr(wchar_t **str)
{
// TODO: Add your implementation code here
ULONG cb=60;
wchar_t *tmp;
tmp=(wchar_t*)CoTaskMemAlloc(cb);
tmp=L"Hello World!";
str=&tmp;
return S_OK;
}
and the CLSID is CLSID_Tpsz,interface ID is IID_ITpsz;
then I want to get the string and display on client,look:
void main()
{
HRESULT hr;
hr=CoInitialize(NULL);
if(FAILED(hr))
{
MessageBox(NULL,L"Initial COM Fail",L"Caption",MB_OK);
return;
}
ITpsz *pITpsz=NULL;
hr=CoCreateInstance(CLSID_Tpsz,NULL,CLSCTX_INPROC_SERVER,IID_ITpsz,(void**)&
pITpsz);
if(FAILED(hr))
{
MessageBox(NULL,L"Create object fail",L"Caption",MB_OK);
return;
}
wchar_t *str=NULL;
hr=pITpsz->PrtStr(&str);
if(FAILED(hr))
{
MessageBox(NULL,L"Get Inteface fail",L"Caption",MB_OK);
}
MessageBox(NULL,str,L"Caption",MB_OK);
CoTaskMemFree(str);
pITpsz->Release();
CoUninitialize();
}
but I display nothing,why?how to solve?Thanks very much.