Drorsh
December 6th, 2004, 06:58 AM
Hello
i m trying to save an object file that is inside a word doc (pic for example) to some other place.
I know that Com Object does not save the data same as files
so i m trying to use persisted CLSID but i m not succeding...
Here is me code - i m opening iStorge for each object in the doc but not finding a persiste...
i would b greatfull for any help u can give me
hr = StgOpenStorage(L"c:\\yalla2\\LetsC.doc", NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pStg);
if (hr != S_OK)
return 0;
IStorage* pBen = NULL;
IStorage* pBenShelBen = NULL;
BSTR sObjectCLSID;
_bstr_t sMyClsid;
_bstr_t sMyName;
ULONG iNothing; // Just a counter
string tempName; // for output file name - in c:\\..
unsigned long iD = 0;
IStream* pStreamBem = NULL; // The stream that will be written to the file
_bstr_t name; // Of stream
// Getting the object pool
hr = pStg->OpenStorage(L"ObjectPool", NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pBen);
// Getting all the objects
hr = pBen->EnumElements(0, NULL, 0, &pEnumStg);
if (hr != S_OK)
return 0;
hr = pEnumStg->Next(1, &stt, NULL);
while (hr == S_OK)
{
IPersistFile* pPerF = NULL;
IPersistStorage* pPerS = NULL;
IPersistStream* pPerSt = NULL;
StringFromCLSID(stt.clsid, &sObjectCLSID);
sMyClsid = sObjectCLSID;
sMyName = stt.pwcsName;
// Opening an object from the file
hr = pBen->OpenStorage(stt.pwcsName, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pBenShelBen);
if (hr != S_OK)
goto nextObject;
// Checking if the storage has a persist (till now I didn't find
// an object that had a PersistFile interface
hr = pBenShelBen->QueryInterface(IID_IPersistFile, (void**)&pPerF);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
hr = pBenShelBen->QueryInterface(IID_IPersistStorage, (void**)&pPerS);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
hr = pBenShelBen->QueryInterface(IID_IPersistStream, (void**)&pPerSt);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
// Getting the ole stuff stream
hr = pBenShelBen->EnumElements(0, NULL, 0, &pEnumStrm);
if (hr != S_OK)
continue;
iNothing = 1;
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
if (hr != S_OK)
goto nextObject;
// Reading the stream..
name = stt.pwcsName;
pStreamBem = NULL;
hr = pBenShelBen->OpenStream(stt.pwcsName, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
0, &pStreamBem);
hr = pStreamBem->QueryInterface(IID_IPersistFile, (void**)&pPerF);
if (hr == S_OK)
MessageBox(NULL, "Wowo", "Found a persist hara", MB_OK);
char vv[9000];
iD = 0;
hr = pStreamBem->Read(vv, 9000, &iD);
tempName = "c:\\yalla2\\" + sMyName;
dd.open(tempName.c_str(), ios::binary);
dd.write(vv + 4, iD);
dd.close();
nextObject:
// Free stuff and Getting the next object
//SysFreeString(sObjectCLSID);
hr = pEnumStg->Next(1, &stt, NULL);
}
i m trying to save an object file that is inside a word doc (pic for example) to some other place.
I know that Com Object does not save the data same as files
so i m trying to use persisted CLSID but i m not succeding...
Here is me code - i m opening iStorge for each object in the doc but not finding a persiste...
i would b greatfull for any help u can give me
hr = StgOpenStorage(L"c:\\yalla2\\LetsC.doc", NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pStg);
if (hr != S_OK)
return 0;
IStorage* pBen = NULL;
IStorage* pBenShelBen = NULL;
BSTR sObjectCLSID;
_bstr_t sMyClsid;
_bstr_t sMyName;
ULONG iNothing; // Just a counter
string tempName; // for output file name - in c:\\..
unsigned long iD = 0;
IStream* pStreamBem = NULL; // The stream that will be written to the file
_bstr_t name; // Of stream
// Getting the object pool
hr = pStg->OpenStorage(L"ObjectPool", NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pBen);
// Getting all the objects
hr = pBen->EnumElements(0, NULL, 0, &pEnumStg);
if (hr != S_OK)
return 0;
hr = pEnumStg->Next(1, &stt, NULL);
while (hr == S_OK)
{
IPersistFile* pPerF = NULL;
IPersistStorage* pPerS = NULL;
IPersistStream* pPerSt = NULL;
StringFromCLSID(stt.clsid, &sObjectCLSID);
sMyClsid = sObjectCLSID;
sMyName = stt.pwcsName;
// Opening an object from the file
hr = pBen->OpenStorage(stt.pwcsName, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
NULL, 0, &pBenShelBen);
if (hr != S_OK)
goto nextObject;
// Checking if the storage has a persist (till now I didn't find
// an object that had a PersistFile interface
hr = pBenShelBen->QueryInterface(IID_IPersistFile, (void**)&pPerF);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
hr = pBenShelBen->QueryInterface(IID_IPersistStorage, (void**)&pPerS);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
hr = pBenShelBen->QueryInterface(IID_IPersistStream, (void**)&pPerSt);
if (hr == S_OK)
MessageBox(NULL, "Wowo Mamash", "Found a persist hara", MB_OK);
// Getting the ole stuff stream
hr = pBenShelBen->EnumElements(0, NULL, 0, &pEnumStrm);
if (hr != S_OK)
continue;
iNothing = 1;
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
hr = pEnumStrm->Next(1, &stt, NULL);
if (hr != S_OK)
goto nextObject;
// Reading the stream..
name = stt.pwcsName;
pStreamBem = NULL;
hr = pBenShelBen->OpenStream(stt.pwcsName, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
0, &pStreamBem);
hr = pStreamBem->QueryInterface(IID_IPersistFile, (void**)&pPerF);
if (hr == S_OK)
MessageBox(NULL, "Wowo", "Found a persist hara", MB_OK);
char vv[9000];
iD = 0;
hr = pStreamBem->Read(vv, 9000, &iD);
tempName = "c:\\yalla2\\" + sMyName;
dd.open(tempName.c_str(), ios::binary);
dd.write(vv + 4, iD);
dd.close();
nextObject:
// Free stuff and Getting the next object
//SysFreeString(sObjectCLSID);
hr = pEnumStg->Next(1, &stt, NULL);
}