Hi,
I need to know the name of attached file in a message so I can retrieve it using GetAttachment(). Do any one know a way I could retrieve the file name from the $File field on the document?
I am trying this, but it returns empty string !
HRESULT hr;
IDocument* pDocument;
IItem* pitem;
VARIANT val;
VariantInit(&val);
val.vt = VT_ARRAY | VT_BSTR;
LONG lstart, lend;
LONG idx = -1;
LONG nPos;
BSTR* pbstr;
long len;
BSTR file;
file=SysAllocString(L"$File"
pDocument->GetFirstItem(file,&pitem);
if (pitem != NULL)
{
pitem->get_Values(&val);
//Get the array values
SAFEARRAY *sa = V_ARRAY( &val );
hr = SafeArrayGetLBound( sa, 1, &lstart);
if(FAILED(hr)) return hr;
hr = SafeArrayGetUBound( sa, 1, &lend);
if(FAILED(hr)) return hr;
hr = SafeArrayAccessData(sa,(void HUGEP**)&pbstr);
if(SUCCEEDED(hr))
{
for(idx=lstart; idx <= lend; idx++)
{
BSTR s;
s = pbstr[idx];
wprintf(L"\nName: %s",s ); //prints null
}
hr = SafeArrayUnaccessData(sa);
if(FAILED(hr)) return hr;
}
else
return hr;
Thanks,
Jay
I need to know the name of attached file in a message so I can retrieve it using GetAttachment(). Do any one know a way I could retrieve the file name from the $File field on the document?
I am trying this, but it returns empty string !
HRESULT hr;
IDocument* pDocument;
IItem* pitem;
VARIANT val;
VariantInit(&val);
val.vt = VT_ARRAY | VT_BSTR;
LONG lstart, lend;
LONG idx = -1;
LONG nPos;
BSTR* pbstr;
long len;
BSTR file;
file=SysAllocString(L"$File"
pDocument->GetFirstItem(file,&pitem);
if (pitem != NULL)
{
pitem->get_Values(&val);
//Get the array values
SAFEARRAY *sa = V_ARRAY( &val );
hr = SafeArrayGetLBound( sa, 1, &lstart);
if(FAILED(hr)) return hr;
hr = SafeArrayGetUBound( sa, 1, &lend);
if(FAILED(hr)) return hr;
hr = SafeArrayAccessData(sa,(void HUGEP**)&pbstr);
if(SUCCEEDED(hr))
{
for(idx=lstart; idx <= lend; idx++)
{
BSTR s;
s = pbstr[idx];
wprintf(L"\nName: %s",s ); //prints null
}
hr = SafeArrayUnaccessData(sa);
if(FAILED(hr)) return hr;
}
else
return hr;
Thanks,
Jay