Need Help Utilizing Office .NET Interop API in ANSI C?

sir_kristopher

New member
0 down vote favorite


I'm working on an open source project that is written in low-level ANSI C (I have no control over this). I am trying to integrate the Microsoft Office Interop functionality into the Windows build of this project. Specifically, I would like to make use of these functions to generate Excel workbooks.

If this was in C# or C++, this wouldn't be a problem for me as I've done it numerous times. But I am completely stumped on how to do this in low-level C! The DLL I need to take this from is Microsoft.Office.Interop.Excel.dll. In C#, it would go something like this:

using Microsoft.Office.Interop.Excel;

public static class Excel
{
private static Microsoft.Office.Interop.Excel.Application m_oExcelApp;
private static Microsoft.Office.Interop.Excel.Workbooks m_oBooks;
private static Microsoft.Office.Interop.Excel._Workbook m_oBook;
private static Microsoft.Office.Interop.Excel._Worksheet m_oSheet;
private static Microsoft.Office.Interop.Excel.Range excelRange;

public static void MakeBook()
{
m_oExcelApp = new Microsoft.Office.Interop.Excel.Application();
m_oExcelApp.Visible = false;
m_oSheet = null;
m_oBooks = null;
excelRange = null;

....and so-on. I would be really happy if I could just get this far! But as far as I can tell, DllImport only allows you to import functions; i.e. I can't figure out how it would be used to instantiate an object within that DLL (i.e. creating an instance of Microsoft.Office.Interop.Excel.Application(), which is required to make any use of these libraries).

Please understand that I fully realize what a daunting task this is, and doing this in low-level C was NOT my choice! But I'm stuck with it, I'm on a somewhat tight deadline, and if any of you are more versed in low-level C than I am and can help me port the above code over, I would be EXTREMELY grateful for your help!

Furthermore, please understand that what I need isn't just a link to an article or some advice on how to do this conceptually. In fact, I already know that the best way to do this would be to use DllImport in conjuction with an opaque handle that would utilize COM functions written to wrap the methods therein (as you can see, I've already done quite a bit of research on this).

My problem is that, I cannot for the life of me figure out how to translate what I just described into low-level C code! What I need is a very basic bit of sample code, preferably a simple port of the C# code I posted above, to get me started. I realize that this is a very difficult question, but a lot of people are counting on me to make this happen and right now I am so overwhelmed with lengthy MSDN articles and concepts that I'm completely stumped on how to just bleeping do it.


So please, if you can throw me an actual *example* of how this would be done in ANSI C, I'd be eternally grateful! Again, what I need is some example code to get me started, not comments about how crappy a language this is to do it in (I know that already) or links to vague articles that describe conceptually what I already know. Thanks!
 
Back
Top