Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Out of Memory Problem in Word Automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thierry Marneffe - 02 Apr 2005 13:26 GMT
Hello

I use Visual C++ to automate the creation of a Word document.
All is working fine, I insert header, footer, Toc, ....
In the last application I'm developping, I need to insert a lot of jpeg
file. From 10 to 200 (and some times more), each beeing 100 to 200 Kb size.
I tried by adding picture that are saved to the word doc and then by simply
linking to an external file....
In both case (but later when doing external link), I got a small window 'Out
of Memory' ...

What shoudl I do to avoid this ? I guess having a 30 Mb file is not that
much with today's computers .... I got 512 MB on memory board and plenty of
space on the hard disk.....
I use UndoClear command too...

Thansk for any clue solving this

Thierry

Here is the typical code I'm using :

#define vtTrue           COleVariant(( short) TRUE)
#define vtFalse          COleVariant(( short) FALSE)
#define vtOptional       COleVariant(( long) DISP_E_PARAMNOTFOUND, VT_ERROR)
#define IntToVt( nInt) ( COleVariant(( short) nInt, VT_I2))

   // Get In-Line Shapes

   InlineShapes WordInlineShapes = WordSelection.GetInlineShapes();
   InlineShape WordInlineShape = ( InlineShape) NULL;

   WordSelection.InsertParagraph();

   Range WordPicRange = WordSelection.GetRange();

   // Set Source Range
   // Note: AddPicture requires aVARIANT as the Range Parameter

   LPDISPATCH lpPicDisp = WordPicRange;

   VARIANT vtDisp;
   vtDisp.vt = VT_DISPATCH;
   vtDisp.pdispVal = lpPicDisp; // Assign IDispatch pointer of Range to
Variant

    // Add Picture

       if ( bLinkedToFile)
           WordInlineShape = WordInlineShapes.AddPicture( strPicPath,
                                                   vtTrue, //LinkToFile
                                                      vtFalse,
//SaveWithDocument
                                                                &vtDisp);
       else
           WordInlineShape = WordInlineShapes.AddPicture( strPicPath,
                                                     vtFalse, //LinkToFile
                                                       vtTrue,
//SaveWithDocument
                                                                  &vtDisp);

   WordSelection.MoveDown( vtUnitLine, IntToVt(15), vtFalse);

   // Clean Up

   WordPicRange.DetachDispatch();

   if ( WordInlineShape != ( InlineShape) NULL)
       WordInlineShape.ReleaseDispatch();
   WordInlineShapes.ReleaseDispatch();
Word Heretic - 04 Apr 2005 08:08 GMT
G'day "Thierry Marneffe" <Thierry.Marneffe@skynet.be>,

Out of memory means an internal buffer was about to overflow, not you
have exceeded total memory footprint.

In your case, I would suggest turning screenupdating on for the
picture insert, then back off again. A Save As can also help things as
well.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

Thierry Marneffe reckoned:

>Hello
>
[quoted text clipped - 66 lines]
>        WordInlineShape.ReleaseDispatch();
>    WordInlineShapes.ReleaseDispatch();
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.