Need to call functions in Unmanaged C++ Dll from VSTO/C# Add-In

Answered 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
     
     Odpovědět

    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)

    http://www.treukhov.com/Kb.aspx?IDispatch_interface_Pinvoke 

  • 11. srpna 2012 22:40
     
     
    Thanks for going where others fear to tred :)

    I'll give this a go later this evening and let you know how it goes.