Need to call functions in Unmanaged C++ Dll from VSTO/C# Add-In
-
10. srpna 2012 15:30
I am writing an application which must load a dll written in unmanaged c++ and execute an exported function
THE DECLARATION IN THE DLL:
extern "C" __declspec(dllexport) __stdcall void MyFunc( IDispatch* pDispApp );
FROM C#
[DllImport("MyDll.dll", EntryPoint="MyFunc")]
public static extern void MyFunc([MarshalAs(UnmanagedType.IDispatch)ref Object dispVar );
MyFunc( "THIS IS WHERE I AM LOST") <----- What goes in here? I need to pass an IDispatch pointer (Outlook Application Object)
I haven't found a sample yet.- Upravený TSRACT 11. srpna 2012 22:42 clarification
Všechny reakce
-
11. srpna 2012 6:00
i;m not sure but i would try using Marshal class and function like GetIUnknownForObject and later query for IDispatch (or use standard .net techniques and define IDispatch interface in .net and simply use casting). Also i would change your dllimport signature from ref object to simply IntPtr (or that IDispatch if you will define it in .net)
- Navržen jako odpověď Leo_GaoModerator 20. srpna 2012 0:47
- Označen jako odpověď Leo_GaoModerator 20. srpna 2012 1:29
-
11. srpna 2012 22:40Thanks for going where others fear to tred :)
I'll give this a go later this evening and let you know how it goes.