[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

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

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
jkcompute
Asked:
jkcompute
1 Solution
 
jkrCommented:
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
 
parnassoCommented:
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
 
sarabandeCommented:
for mixed code assemblies you may search for IJW (it just works) what was the slogan used by ms regarding those assemblies.

Sara
0
 
jkcomputeAuthor Commented:
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
 
jkcomputeAuthor Commented:
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now