Solved

Doc file creation

Posted on 1998-04-07
1
358 Views
Last Modified: 2013-11-20
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.AllocSysString() , &wordID);

    ILockBytes* pLock = NULL;
    hRes = CreateILockBytesOnHGlobal(NULL, TRUE , &pLock);

    IStorage* pTmpStor;
    hRes = StgCreateDocfileOnILockBytes(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.AllocSysString() ,
        STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStor);

    hRes = pPersist->InitNew(pStor);
    hRes = pPersist->Save(pStor, TRUE);
    hRes = pPersist->SaveCompleted(pStor);

    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 ?

0
Comment
Question by:jaba
1 Comment
 

Accepted Solution

by:
dr_funfrock earned 200 total points
ID: 1317508
Jaba

 What you are loading is the property information for the file not the actual file text. To load the actual winword viewer you need to be an Doc Object Container.

Doc

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now