Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need C++ help to get file names from $File...

Status
Not open for further replies.

jaydave6

Programmer
Jan 2, 2002
13
IN
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&quot;\nName: %s&quot;,s ); //prints null
}
hr = SafeArrayUnaccessData(sa);
if(FAILED(hr)) return hr;
}
else
return hr;


Thanks,
Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top