Solved

Calling managed code (Microsoft office interop) from unmanged c+= cde

Posted on 2011-03-10
5
650 Views
Last Modified: 2012-06-21
I need to call Microsoft.office.interop.word.dll from an older c++ appliacion. (Written with Visual Studio 6) .
I have read several articcles athat say you can call a managed library from unmanaged code but I cannot find an example or walkthrough on it. I have also rad of "Mixed Mode images" solving this problem but have no examples of implementing it.

Any samples would be greatly applreciated.
0
Comment
Question by:jkcompute
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 35097079
Well, the title of the following article might be a bit misleading, but it's a detailed walkthorugh to what you want to do: http://www.codeproject.com/KB/COM/ComHard.aspx ("COM Interop the Hard Way") - COM Interop (http://msdn.microsoft.com/en-us/library/kew41ycz%28VS.71%29.aspx - "Introduction to COM Interop") allows you to call .NET assemblies as COM objects from unmanaged code.
0
 
LVL 4

Expert Comment

by:parnasso
ID: 35097245
If you just want a C++ console application, you can do it by creating a .NET runtime host, instantiate any type of Microsoft.office.interop.word.dll and use it entirely in C++ code, no COM needed.

Find an example in the following Microsoft sample application:

CppHostCLR
0
 
LVL 34

Expert Comment

by:sarabande
ID: 35107578
for mixed code assemblies you may search for IJW (it just works) what was the slogan used by ms regarding those assemblies.

Sara
0
 

Author Comment

by:jkcompute
ID: 35148922
I went with JKR's solution, except Iwimped out and made it real easy.  I decided to just write a managed app to convert rtf files to doc files as a way to start.  This is critical because my main app is a windows service and real hard to degug.  Microsoft Interop word functions are a nightmare with security because there is a bug in the reg APPID keys tht show up if installl Word before the framework, there are also some versionissues if you do not develop on themachine that will run the service.  to make a long story short, I got the app mostly running.  Instead of converting it to a dll file, I simly call it from within my service, passing command line params instead of function params.  It is work great. (I go for fujctional and not programming purity).

I still have one small problem that I am hoping someone can shed light on.  Code samples for C++ interop are very rare and hard to find, so I translate from VB.  A vp 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 will accept JKR's solution after waitng a few days to see if I get any new comments on this translation issue.
       
0
 

Author Closing Comment

by:jkcompute
ID: 35165267
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

687 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