2

We got a homework assignment to create a Microsoft Word document using Visual Studio 2005 and C++. Could anyone explain how this could be done. I was trying to do it using VSTO, but I've had no luck. All resources on the internet I could find explain how this could be done in VB or C#, but I need some C++ examples. Thanks

EDIT: Accepted format is .doc.

Coral Doe
  • 1,925
  • 3
  • 19
  • 36

4 Answers4

2

Apparently VSTO is not available for C++.

Does this MSDN article help?:

Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
2

Take a look at Use OLE Automation from a C Application Rather Than C++. That will show you the plain way to access the OLE automation interface for Word.

For methods, properties, use the Object Browser which you can access by selecting Tools -> Macro -> Visual Basic Editor. Press F2 to invoke the object browser.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
0

You can do this using Mircosoft Office's Primary Interop Assemblies. Doing this with C++ is not as difficult as it seems. you need to turn on Common Language Runtime support from project properties and then you can simply do a #using statement on the Mircosoft.Office.Interop.dll.

After that you should be OK to use the interop assembly as you want. In C++, you access .NET classes a little different i.e., replacing . with :: Something like...

Microsoft::Office::Interop::Word^ wordObj = new Microsoft::Office::Interop::Word();

Microsoft Office 2003 PIAs
Microsoft Office 2007 PIAs

Aamir
  • 14,882
  • 6
  • 45
  • 69
  • 1
    C++ and C++/CLI are really two separate languages (although they are similar). As this is a homework assignment I presume the answer needs to be in pure C++. (Not -1ing this just in case the OP just needs to get something done any way he can, in which case your answer could still be helpful.) – j_random_hacker Jun 23 '09 at 15:56
-1

Here is a spec of the binary Word document format. You could easily roll your own implementation.

http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 1
    It should be made more clear that this answer is sarcasm. A lot of clever people have spent a lot of time trying to reimplement the .doc format. Doing this for a homework assignment would be non-trivial. – Colin Pickard Jun 23 '09 at 12:02
  • An article by Joel explaining why this would be a rather bad idea: http://www.joelonsoftware.com/items/2008/02/19.html – John Carter Jun 23 '09 at 12:05
  • This is not sarcasm. He did not originally note what the requirements were - whether to use another library or not. – Daniel A. White Jun 23 '09 at 12:06
  • Hehe... Whenever my free-software-adoring workmates have trouble with the way some enormous program (e.g. Firefox) works, I always like to remind them that they're free to make any changes they want since the source code is available -- all X million lines of it :) – j_random_hacker Jun 23 '09 at 16:02
  • I like the proposed answer though! – swdev Aug 11 '11 at 06:56