Solved

Doc file creation

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 36
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 114
sumHeights  challenge 17 80
Problem to App 4 120
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: 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 …
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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