Wincom and Word example

This example puts "This is a title" centered on the page, underlined, and in bold.
DEFINE wdapp INTEGER
DEFINE wddoc INTEGER
MAIN
  DEFINE result INTEGER
--initialization of global variables
  LET wdapp = -1
  LET wddoc = -1
--first, we must create an Instance of a Word Application
  CALL ui.Interface.frontCall("WINCOM","CreateInstance",
   ["Word.Application"],[wdapp]) 
  CALL CheckError(wdapp, __LINE__)
--then adding a document
  CALL ui.Interface.frontCall("WINCOM","CallMethod",
   [wdapp,"Documents.Add"],[wddoc])
  CALL CheckError(wddoc, __LINE__)
--then, setting it to be visible
  CALL ui.Interface.frontCall("WINCOM","SetProperty",
   [wdapp,"Visible",true],[result])
  CALL CheckError(result, __LINE__)
--Centering the cursor for the title
  CALL ui.Interface.frontCall("WINCOM","SetProperty",
   [wdapp,"Selection.ParagraphFormat.Alignment","1"],[wddoc])
  CALL CheckError(wddoc, __LINE__)
--Underlining the title
  CALL ui.Interface.frontCall("WINCOM","SetProperty", 
   [wdapp,"Selection.Font.Underline","1"],[wddoc])
  CALL CheckError(wddoc, __LINE__)
--Putting the title in bold
  CALL ui.Interface.frontCall("WINCOM","SetProperty",
   [wdapp,"Selection.Font.Bold","9999998"],[wddoc])
  CALL CheckError(wddoc, __LINE__)
--Typing the title's text
  CALL ui.Interface.frontCall("WINCOM","CallMethod", 
   [wdapp,'Selection.TypeText("This is a title")'],[wddoc])     
  CALL CheckError(wddoc, __LINE__)
--then Free the memory on the client side
  CALL freeMemory()
END MAIN

FUNCTION freeMemory()
  DEFINE res INTEGER
  IF wddoc != -1 THEN
    CALL ui.Interface.frontCall("WinCOM","ReleaseInstance", [wddoc], [res] )
  END IF
  IF wdapp != -1 THEN
    CALL ui.Interface.frontCall("WinCOM","ReleaseInstance", [wdapp], [res] )
  END IF
END FUNCTION

FUNCTION checkError(res, lin)
  DEFINE res INTEGER
  DEFINE lin INTEGER
  DEFINE mess STRING
  IF res = -1 THEN
    DISPLAY "COM Error for call at line:", lin
    CALL ui.Interface.frontCall("WinCOM","GetError",[],[mess])
    DISPLAY mess
--let's release the memory on the GDC side
    CALL freeMemory()
    DISPLAY "Exit with COM Error."
    EXIT PROGRAM (-1)
  END IF
END FUNCTION