Hello everyone,
Now I want to read and write picture stream from contact items ,but I failed
with the following code,can you give me some advance please.
// IPOutlookApp2 * polApp = NULL;
// IContact * pContact = NULL;
IStream * istream = NULL;
BYTE* buf = NULL ;
STATSTG stg;
IItem * iitem = NULL;
CEPROPID propid = PIMPR_PICTURE;
CEOID oid;
//hr = pItems->Item(i,(IDispatch**)&pContact);//there is no problem to
get pContact
hr = pContact->get_Oid((long*)&oid);
hr = polApp->GetItemFromOidEx(oid, 0, &iitem);
if (iitem != NULL)
{
hr = iitem->OpenProperty(propid, GENERIC_READ | GENERIC_WRITE,
&istream);
}
readSize = 0;
if ( hr != 0 )
{
return GetLastError();
}
hr = istream->Stat(&stg, STATFLAG_NONAME ); //I want to get the real
size of istream
if (hr !=0)
{
return GetLastError();
}
hr = istream->Read(buf, stg.cbSize.LowPart, (ULONG*)&readSize );//I dont
know wether this works or not

Executing it for the first time ,istream is not NULL,but
hr=istream->Stat(...) is 0x80004001 and GetLastError is 0x00000000;Then the
second time,hr returned by iitem->OpenProperty(propid, GENERIC_READ |
GENERIC_WRITE, &istream) is 0x80070020 and GetLastError is 0x00000020.
I have no idea what the problem is ,give me some tips please.
Thank you in advance.

Re: How to read and write PIMPR_PICTURE property? by Peter

Peter
Thu Aug 09 05:12:22 CDT 2007

Stat is not implemented on all IStream implementations. Instead you can keep
reading in a loop until no more data is read. The reason a subsequent
OpenProperty call fails is that you can only open the property once at a
time, you must have missed freeing the original IStream.

Also you can simplify your code to get the IItem interface - instead of
retrieving the OID and then getting the IItem for the OID, use
QueryInterface to get the IItem interface from your IContact.

Peter

--
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

"sophia" <lhxsky@163.com> wrote in message
news:uvhY$Zl2HHA.1204@TK2MSFTNGP03.phx.gbl...
> Hello everyone,
> Now I want to read and write picture stream from contact items ,but I
> failed with the following code,can you give me some advance please.
> // IPOutlookApp2 * polApp = NULL;
> // IContact * pContact = NULL;
> IStream * istream = NULL;
> BYTE* buf = NULL ;
> STATSTG stg;
> IItem * iitem = NULL;
> CEPROPID propid = PIMPR_PICTURE;
> CEOID oid;
> //hr = pItems->Item(i,(IDispatch**)&pContact);//there is no problem to
> get pContact
> hr = pContact->get_Oid((long*)&oid);
> hr = polApp->GetItemFromOidEx(oid, 0, &iitem);
> if (iitem != NULL)
> {
> hr = iitem->OpenProperty(propid, GENERIC_READ | GENERIC_WRITE,
> &istream);
> }
> readSize = 0;
> if ( hr != 0 )
> {
> return GetLastError();
> }
> hr = istream->Stat(&stg, STATFLAG_NONAME ); //I want to get the real
> size of istream
> if (hr !=0)
> {
> return GetLastError();
> }
> hr = istream->Read(buf, stg.cbSize.LowPart, (ULONG*)&readSize );//I
> dont know wether this works or not
>
> Executing it for the first time ,istream is not NULL,but
> hr=istream->Stat(...) is 0x80004001 and GetLastError is 0x00000000;Then
> the second time,hr returned by iitem->OpenProperty(propid, GENERIC_READ |
> GENERIC_WRITE, &istream) is 0x80070020 and GetLastError is 0x00000020.
> I have no idea what the problem is ,give me some tips please.
> Thank you in advance.
>
>
>
>
>