Out of Memory Problem in Word Automation

  • Thread starter Thierry Marneffe
  • Start date
T

Thierry Marneffe

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();
 
W

Word Heretic

G'day "Thierry Marneffe" <[email protected]>,

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top