Solved

Doc file creation

Posted on 1998-04-07
1
363 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 82
iSeries DB2 Query 2 95
pre4 challenge 19 100
Bartender label printing - switch on and off graphics 3 36
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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