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.Intero开发者_JAVA技巧p.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!
Thanks!
EDIT: I appreciate the conceptual advice, but what I really need is some example C code to show me how to actually make it happen! Please guys, somebody has to be able to help me with this! I don't need a lot, just a small example showing me how to do it in the context of what I'm trying to do, and I can handle it from there.
It might be easier to wrap the object as an opaque handle, and then wrap the methods you want to use in C as COM functions that take the opaque handle. For more information, this MSDN article might be a good place to start.
精彩评论