views:

665

answers:

6

Hi. 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.

+1  A: 

Apparently VSTO is not available for C++.

Does this MSDN article help?:

Colin Pickard
But is is possible to do this in some other way?
try this MSDN article: http://support.microsoft.com/kb/316207
Colin Pickard
A: 

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
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
A: 

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
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
An article by Joel explaining why this would be a rather bad idea: http://www.joelonsoftware.com/items/2008/02/19.html
therefromhere
Rolling your own is not hard if .docx is acceptable ;-)
Sinan Ünür
This is not sarcasm. He did not originally note what the requirements were - whether to use another library or not.
Daniel A. White
This *is* homework after all ;-)
Sinan Ünür
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
+2  A: 

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
+1  A: 

I think this might help: http://stackoverflow.com/questions/145573/creating-opening-and-printing-a-word-file-from-c

Please check especially the main function on example 2 since there it is shown how to start Word and make it visible.

Citrone
A: 

Hi all. Are anyone know how write some data into storage...not meta data. This data must be not overwritten by ms-word on "save as", and not deleted some meta clean utilities? Thanks!

alex