What is the best way to call MSWord from C++
What is the best way to call MSWord from C++
I never did this before. I always used VB6 and the Word-COM-Library: C:\Program Files\Microsoft Office\OfficeXX\MSWORD.olb
Respectively:
Microsoft Word XX.0 Object Library
- How should I use/call Word from C++ (VS2010) ?
- Should I use .NET ? (C++CLI)
- Do you have a good step by step explanation?
Code example 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.Paragr开发者_Go百科aphs.Count
Debug.Print CStr(mMaxParagraph)
aDoc.Close
mWord.Quit
End Sub
Doing COM in C++ isn't that painful as long as you're using ATL smart COM pointers. You simply need to #import
the type library and this will create a whole bunch of smart pointer classes that you can use in your application.
Doing COM in native C++ is an exercise in pain. You might be best off using C++/CLI, which gives you all the features of C++ plus the ability to interact with .NET stuff easily.
精彩评论