E
excelthoughts
I am trying to pass an Excel.Application object from c# to c++ DLL via
PInvoke.
The c++ code expects an IDispatch.
The Pinvoke Wizard paulyao.com suggests:
[DllImport("myDLL.dll")]
public static extern short Initialise(ref LPDISPATCH pExcel);
so I have tried this code c#:
[DllImport("myDLL.dll")]
public static extern short
Initialise([MarshalAs(UnmanagedType.IDispatch)]ref object pExcel);
and
[DllImport("myDLL.dll")]
public static extern short
Initialise([MarshalAs(UnmanagedType.IUnknown)]ref object pExcel);
And this is the code that calls the routine.
Excel.Application excelApp= (Excel.Application)application; //(from
Connect class in COM Addin)
object o=(object)excelApp;
Initialise(ref o);
When the c++ code is called it throws a COleDispatchException error.
m_wCode is 00000000 and 80020005 respectively.
Any ideas on how I should pass the Excel Application object?
Regards
Andrew
PInvoke.
The c++ code expects an IDispatch.
The Pinvoke Wizard paulyao.com suggests:
[DllImport("myDLL.dll")]
public static extern short Initialise(ref LPDISPATCH pExcel);
so I have tried this code c#:
[DllImport("myDLL.dll")]
public static extern short
Initialise([MarshalAs(UnmanagedType.IDispatch)]ref object pExcel);
and
[DllImport("myDLL.dll")]
public static extern short
Initialise([MarshalAs(UnmanagedType.IUnknown)]ref object pExcel);
And this is the code that calls the routine.
Excel.Application excelApp= (Excel.Application)application; //(from
Connect class in COM Addin)
object o=(object)excelApp;
Initialise(ref o);
When the c++ code is called it throws a COleDispatchException error.
m_wCode is 00000000 and 80020005 respectively.
Any ideas on how I should pass the Excel Application object?
Regards
Andrew