en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en nl en en en en en en en en en de en en en en en nl en en en en en en en en en en en en nl en en en en en en en en en en en en en en nl en en en en en en en fr en da en en en en en en en nl en en en en en en en en en en en en nl en en en en en en eu en en en en nl vi en en en en en en en en en en en en de en en en fr en en en en en en en en en pt en en en en en en
By logging into your account, you agree to our Privacy Policy, personal data processing and storage practices as described therein.
Forgot password or user name?
Search in titles only Search in Working with Objects only
You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Memory Access Violation when running the Word COM sample
All Time Today Last Week Last Month
All Discussions only Photos only Videos only Links only Polls only Events only
26 Jan 2009, 03:50 AM
Maybe I am missing the obvious, but when I run the PB 9.0 Word COM Sample my Win XP computer (Word 2000 installed), I get a "Memory Access Violation" when I try to save the document to disk. But if I replace the "SaveAs" method with the "Save" method, the user is prompted with a "Save File" dialog and all ends well.
The PB 8.0 Word COM sample runs fine. Of course I see that the PB 9.0 sample was designed for and tested with a later Office Version (2003) than the version I use, but aren't the object definitions in the word.inc file kept "version independent"?
Any help would be appreciated!
'============================================================================== ' ' oWord.bas example for PowerBASIC For Windows Compiler ' Copyright (c) 2002-2008 PowerBASIC, Inc. ' All Rights Reserved. ' ' Run a short demonstration of sending data to Microsoft Word. ' Tested with MS Word v11.00 (Office 2003) ' '============================================================================== #COMPILER PBWIN 9 #COMPILE EXE #DIM ALL ' oWord.inc contains the Micorosft Word Interface defintions ' created with the PowerBASIC COM Browser #INCLUDE "oWord.inc" ' Main application entry point... FUNCTION PBMAIN() LOCAL oWordApp AS Int__Application ' Application Interface LOCAL oWordDoc AS Int__Document ' Document Interface LOCAL oWordSel AS Selection ' Selection Interface LOCAL sProgID_Word AS STRING LOCAL iDocCount AS LONG LOCAL tText AS STRING LOCAL vText AS VARIANT LOCAL vFileFmt AS VARIANT MSGBOX "About to Open MSWORD..." ' Open an instance of MSWORD oWordApp = NEWCOM $PROGID_Application ' Could MSWORD be opened? If not, terminate this app IF ISFALSE ISOBJECT(oWordApp) THEN MSGBOX "Unable to open or start MSWORD!" EXIT FUNCTION END IF ' Make MSWORD visible in for example normal show state oWordApp.Visible = 1 oWordApp.WindowState = %wdWindowStateNormal ' Get the current document count from the "documents collection" MSGBOX "About to request the MSWORD document count..." iDocCount = oWordApp.Documents.Count MSGBOX "MSWORD has " & FORMAT$(iDocCount) & " File(s) loaded!" ' Add a document to the "documents collection", and obtain a reference ' to the document Interface for the new document MSGBOX "Adding a new document to MSWORD..." oWordDoc = oWordApp.Documents.Add IF ISFALSE ISOBJECT(oWordDoc) THEN MSGBOX "MSWORD was not able to start a new document." & $CR & _ "Please ensure MSWord and VBA are installed." GOTO Terminate END IF ' Get the current document count from the "documents collection" ' This should be one value higher than before MSGBOX "Checking the MSWORD document count again..." iDocCount = oWordApp.Documents.Count MSGBOX "MSWORD has " & FORMAT$(iDocCount) & " File(s) loaded!" ' Get the Interface to the currect selection of the document oWordSel = oWordApp.Selection ' Enter some text into the document at the selection position MSGBOX "..and placing some text at that selection point..." oWordSel.TypeText(UCODE$("PowerBASIC controls Microsoft Word!")) ' Set a paragraph marker (end of paragraph) oWordSel.TypeParagraph ' Another paragraph oWordSel.TypeText(UCODE$("COM client controls a COM server!")) oWordSel.TypeParagraph ' Save the new document to disk MSGBOX "About to save the document and close MSWORD..." vText = "Test.doc" vFileFmt = %wdFormatDocument oWordDoc.SaveAs(vText, vFileFmt) <======= Exception 'Memory Access Violation; Program tried to read or write an invalid 'memory address 'oWordDoc.Save would work MSGBOX "All done! The COM automation stuff is pretty cool!" Terminate: ' Close the current document and then close MSWORD completely oWordApp.ActiveWindow.CLOSE oWordApp.Quit ' Close all of the Interfaces oWordSel = NOTHING oWordDoc = NOTHING oWordApp = NOTHING END FUNCTION
Join Date: Mar 2004
26 Jan 2009, 05:47 AM
The PB 8.0 Word COM sample runs fine. Of course I see that the PB 9.0 sample was designed for and tested with a later Office Version (2003) than the version I use, but aren't the object definitions in the word.inc file kept "version independent"?
They should be, but they aren't. Generate a new include file for your version.
Join Date: Sep 2004
26 Jan 2009, 08:00 AM
Heureka! Issue solved. Thank you very much, José!
Is there at least some "upward" version independency i.e. would the inc file derived from the MSWORD9.OLB library file also work with Word 10 or 11?
One last question: Just out of interest, I wanted to test the Word COM sample on my Windows 95 machine with Office 97 installed. PB/WIN ran fine under Windows 95, but the PB COM Browser wouldn't start.
I just wondered, if PB/WIN runs under Windows 95, then why would the PB COM Browser need a higher Windows version? Ok, I know, Windows 95 is hopelessly outdated nowadays, but did anybody have the same issue? Is this maybe just a missing/outdated DLL problem?
Join Date: Aug 1998
26 Jan 2009, 09:57 AM
I just wondered, if PB/WIN runs under Windows 95, then why would the PB COM Browser need a higher Windows version
Probably the same reason you could not use the 'install' program provided for PB/DLL 2.0 (the 16 bit compiler) except on a 32-bit machine.
You had to 'install' on a 32-bit machine, then copy the required files to the 16-bit machine.
Port Washington WI USA
Join Date: Mar 2004
26 Jan 2009, 11:43 AM
Is there at least some "upward" version independency i.e. would the inc file derived from the MSWORD9.OLB library file also work with Word 10 or 11?
Only if you use OBJECT CALL/GET/SET/LET and late binding. As usual, M$ has broken his own rules by renaming methods such SaveAs as SaveAs2000 and adding a new SaveAs method.
Join Date: Sep 2004
27 Jan 2009, 02:53 AM
Thank you for your answers!
Join Date: Sep 2007
27 Jan 2009, 06:12 AM
Is there at least some "upward" version independency i.e. would the inc file derived from the MSWORD9.OLB library file also work with Word 10 or 11?
Only if you use OBJECT CALL/GET/SET/LET and late binding. As usual, M$ has broken his own rules by renaming methods such SaveAs as SaveAs2000 and adding a new SaveAs method.
Microsoft engineers told me years ago (I can't remember which conference) that using the library from the oldest version of an Office program you plan to support would maintain upward-compatibility. As José notes, you can't always get what MS promises.
That said, many methods & properties remain unchanged. Depending on which you call, there may be no problems.
When "inconsistencies" arise, I have found that you can maintain Int__Application/Int__Document and IDISPATCH references to the same Word applicication/document. That way you minimize the need for OBJECT CALL/GET/SET/LET calls to only the changed methods and properties.
Copyright © 1998-2022 PowerBASIC Tools, LLC - All Rights Reserved.
Powered by vBulletin® Version 5.7.0
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
All times are GMT-5. This page was generated at 09:41 PM.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.