What is the best way to call MSWord from C ++

What is the best way to call MSWord from C ++

I have never done this before. I have always used VB6 and Word-COM-Library:C:\Program Files\Microsoft Office\OfficeXX\MSWORD.olb

Respectively:
Microsoft Word XX.0 Object Library

  • How do I use / call Word from C ++ (VS2010)?
  • Should I use .NET? (C ++ CLI)
  • Do you have a good step by step explanation?

Sample code in VB

Option Explicit

Sub Main()
    Dim mWord    As New Word.Application
    mWord.ScreenUpdating = False
    Dim mMaxParagraph  As Long
    Dim aDoc As Word.Document
    Dim aFileName As String
    aFileName = "C:\mydoc.doc"
    Set aDoc = mWord.Documents.Open(aFileName)
    mMaxParagraph = mWord.ActiveDocument.Paragraphs.Count
    Debug.Print CStr(mMaxParagraph)
    aDoc.Close
    mWord.Quit
End Sub
+3
source share
2 answers

Running COM in C ++ is not so painful as long as you use ATL smart COM pointers. You just need #importa type library, and this will create a whole bunch of smart pointer classes that you can use in your application.

+2
source

COM ++ - . ++/CLI, ++ .NET-.

0

Source: https://habr.com/ru/post/1746149/


All Articles