?
Solved

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

Posted on 2011-03-10
5
Medium Priority
?
651 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 2000 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 35

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

752 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