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
Solved

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

Posted on 2011-03-10
5
646 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
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 33

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 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