?
Solved

Doc file creation

Posted on 1998-04-07
1
Medium Priority
?
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
dr_funfrock earned 400 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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