jaba
asked on
Doc file creation
I am going to write some code to create empty WinWord document. I do this:
CString ProgID = "Word.Document";
CLSID wordID;
HRESULT hRes = CLSIDFromProgID(ProgID.All ocSysStrin g() , &wordID);
ILockBytes* pLock = NULL;
hRes = CreateILockBytesOnHGlobal( NULL, TRUE , &pLock);
IStorage* pTmpStor;
hRes = StgCreateDocfileOnILockByt es(pLock,
STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pTmpStor);
IPersistStorage* pPersist = NULL;
hRes = CoCreateInstance(wordID , NULL , CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER ,
IID_IPersistStorage, (void**)&pPersist);
IStorage* pStor = NULL;
CString FileName ("aaa.doc");
hRes = StgCreateDocfile(FileName. AllocSysSt ring() ,
STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStor);
hRes = pPersist->InitNew(pStor);
hRes = pPersist->Save(pStor, TRUE);
hRes = pPersist->SaveCompleted(pS tor);
pPersist->Release();
pStor->Release();
pTmpStor->Release();
pLock->Release();
Really its a full circle if "Save as" operation for OLE document. Because i am creating new object it must be empty. All working ok (each hRes testing to FAILED after every operation). Why after all this actions i am opening aaa.doc buy MS WinWord and see a lot of strange symbols in text ? Why document isnt empty ?
CString ProgID = "Word.Document";
CLSID wordID;
HRESULT hRes = CLSIDFromProgID(ProgID.All
ILockBytes* pLock = NULL;
hRes = CreateILockBytesOnHGlobal(
IStorage* pTmpStor;
hRes = StgCreateDocfileOnILockByt
STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pTmpStor);
IPersistStorage* pPersist = NULL;
hRes = CoCreateInstance(wordID , NULL , CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER ,
IID_IPersistStorage, (void**)&pPersist);
IStorage* pStor = NULL;
CString FileName ("aaa.doc");
hRes = StgCreateDocfile(FileName.
STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStor);
hRes = pPersist->InitNew(pStor);
hRes = pPersist->Save(pStor, TRUE);
hRes = pPersist->SaveCompleted(pS
pPersist->Release();
pStor->Release();
pTmpStor->Release();
pLock->Release();
Really its a full circle if "Save as" operation for OLE document. Because i am creating new object it must be empty. All working ok (each hRes testing to FAILED after every operation). Why after all this actions i am opening aaa.doc buy MS WinWord and see a lot of strange symbols in text ? Why document isnt empty ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.