RosettaCodeData/Task/OLE-automation/FreeBASIC/ole-automation.basic
2024-10-16 18:07:41 -07:00

35 lines
1,002 B
Text

#include "disphelper/disphelper.bi"
dhInitialize(True)
dhToggleExceptions(True)
Dim As IDispatch Ptr wordApp, document, content
Dim As IDispatch Ptr paragraphs, paragraph, rnge
OleInitialize(NULL)
dhCreateObject("Word.Application", NULL, @wordApp)
dhPutValue(wordApp, ".Visible = %b", True)
dhGetValue("%o", @documents, wordApp, ".Documents")
dhCallMethod(documents, "Add", @document)
dhGetValue("%o", @content, document, ".Content")
dhGetValue("%o", @paragraphs, content, ".Paragraphs")
dhCallMethod(paragraphs, "Add", @paragraph)
dhGetValue("%o", @rnge, paragraph, ".Range")
dhPutValue(rnge, ".Text = %s", "This is a Rosetta Code test document.")
Sleep 10000 ' Wait 10 seconds
dhPutValue(document, ".Saved = %b", True)
dhCallMethod(document, "Close(%b)", False)
dhCallMethod(wordApp, "Quit")
SAFE_RELEASE(wordApp)
SAFE_RELEASE(documents)
SAFE_RELEASE(document)
SAFE_RELEASE(content)
SAFE_RELEASE(paragraphs)
SAFE_RELEASE(paragraph)
SAFE_RELEASE(rnge)
OleUninitialize()
dhUninitialize(True)