Link to home
Start Free TrialLog in
Avatar of ugeb
ugebFlag for United States of America

asked on

mixing C++ & C# in Vis Studio 2013

I have two Windows Win32 projects written in C++.  Now that code needs to manipulate Excel (xlsx) and Word (docx) files.  I need a way to manipulate the xlsx and docx files, and I know they are in Office OpenXML format.  Unfortunately, there no longer seem to be any good updated libraries in C++ for doing this.  (I looked at LibOPC but it seems out of date.)

I've learned that C# has some good tools, so I need to mix the C# code into my C++ project in Visual Studio 2013.  

How do I combine these two languages in a single project? Dynamically or Statically linked library?  How can I do this?

( Windows 7, VS 2013)
SOLUTION
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ugeb

ASKER

Thank you both for your comments.  
@Andy, you are correct.  I need to call C# from C++ (one of the projects is Qt based).

I'm not sure how I would use the COM or PInvoke given I'm calling C# from C++ and I cannot wrap the main app in C++, but, as you suggested Andy, I can use Karrtik's solution in reverse.  Let me make sure I understand by outlining the steps:

1) Create one solution, starting with my current Qt application in C++, a win32 project.

2) create a C# dll in the same solution as a "C# Class Library" which handles all the OpenXML  transactions and will pass that along to the C++ main through a C++/CLI library?

3) create a C++/CLI Library in the same solution to be called FROM C++, which in turn will call the C# dll? (What is this project type if separate?)

I'm missing some details here.  Are there more steps?  Is the C++/CLI a separate project from the main, or can it be compiled into it in the same project (from it's own class)?

Thanks!
If you want to call c# from c++ it easy if you don't mind changing the project settings of your c++ project to enable CLR, I think it's in the general settings page.
Once you do this, you can add reference to your .Net library, from project properties, add reference. And once you do this you can invoke c# code from c++.
Thanks,
 Karrtik
Avatar of ugeb

ASKER

I can't change the project settings for a Qt project as it is unmanaged.  What then can I do?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ugeb

ASKER

Thank you both.  I'll start running from here and likely be back with questions ...