Solved

Traslate Office Interop function calls to C++ from VB

Posted on 2011-03-18
4
557 Views
Last Modified: 2012-05-11
Code for (c++) samples for Microsoft Office Interop use are rare and hard to find.  Mostly I translate them from VB to C++ I have having a real problem compiling with one of them.

 . A vb command that works in other apps that I wrote is  
     Dim formatDOC As Object = Word.WdSaveFormat.wdFormatDocument

I have translated it to
Microsoft::Office::Interop::Word::WdSaveFormat*    formatRTF = new   Microsoft::Office::Interop::Word::WdSaveFormat::wdFormatDocument    ;
or simply (both should work)
Word::WdSaveFormat* formatR = new Word::WdSaveFormat::wdFormatDocument;
These line bring the error message -
error C2061: syntax error : identifier 'wdFormatDocument'
I have checked spelling a dozen times.

I have been unable to find any reports of this being turned in as a bug.
Thanks for any insight into this issue.      
0
Comment
Question by:jkcompute
  • 3
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35165497
wdFormatDocument is an enumeration (integer, basically). It doesn't make sense to me to call "new" for an integer. Perhaps that has something to do with it?
0
 

Author Comment

by:jkcompute
ID: 35183627


When I take out the "new"
Word::WdSaveFormat* formatR = new Word::WdSaveFormat::wdFormatDocument;
I get a type mismatch

 cannot convert from 'Microsoft::Office::Interop::Word::WdSaveFormat' to 'Microsoft::Office::Interop::Word::WdSaveFormat __gc *'  
Managed variables are new to me so I am unable to rectify it.

I tried setting the variable that you would put in if you use the comand in Word. Hoping that Microsfot would cast it for me.
Word::WdSaveFormat* formatR = 1;

error C2440: 'initializing' : cannot convert from 'int' to 'Microsoft::Office::Interop::Word::WdSaveFormat __gc *'
or with
Word::WdSaveFormat* formatR = __gc 1;

error C3150: 'constant' : '__gc' can only be applied to a class, struct, interface, array or pointer

any help?
0
 

Accepted Solution

by:
jkcompute earned 0 total points
ID: 36302902
There seems to be no valid solution.  I bought aspose 3rd party library to solve it.
0
 

Author Closing Comment

by:jkcompute
ID: 36327276
Aspose is very expensive, but surely my time is worth something
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now