COM interoperatability using PInvoke (SEH Exception)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Muthiah Samy

    #1

    COM interoperatability using PInvoke (SEH Exception)

    Hi All,

    I am trying to call COM Component in .NET using PInvoke.

    In the following scenario, ( I am getting an exception called SEH -
    External component has thrown an exception)


    UnManaged Code
    ---------------
    virtual HRESULT IDispatch::GetI DSOfNames(const IID & riid, LPWSTR *
    rgizNames, UINT CNames, LCID lcid, DISPID *rgDispID)


    Managed Code (I have rewritten)

    ------------

    int GetIDsOfNames ([In] System.Guid guid, ref System.String[]
    rgNames,[In] System.UInt32 cNames, [In] System.UInt32 lcid,

    [Out] out long[] dispID);


    Public Test()
    {

    AXIDispatch pIScriptDispatc h;
    String[] wszScriptFuncti ons = new String[1];
    wszScriptFuncti ons[0] = "entryMetho d";
    long[] dispIDFunctions = new long[1];

    pIScriptHost.Ge tScriptDispatch (out pIScriptDispatc h);
    IntPtr p = Marshal.GetIDis patchForObject( pIScriptHost);
    IntPtr ppv;
    Marshal.QueryIn terface(p,ref diug,out ppv);
    pIScriptDispatc h = (AXUtil.AXIDisp atch)Marshal.Ge tObjectForIUnkn own(ppv);

    try
    {
    pIScriptDispatc h.GetIDsOfNames (guid,ref wszScriptFuncti ons, 1,
    1033, out dispIDFunctions );
    }
    catch (Exception ex)
    {
    Console.WriteLi ne (ex.ToString ());
    }

    }

    If I execute Test() I will be getting the following Exception for
    Invoking "GetIDsOfNames( ....)"

    System.Runtime. InteropServices .SEHException: External component has
    thrown an exception.



    What could be the reason to get this kind exeception, I don't know
    what to do in order to handle it error. Could anyone

    kindly help me to solve ? I will greatly appreciate.

    Thanks & Regards
    R. Muthiah Samy
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: COM interoperatabil ity using PInvoke (SEH Exception)

    Muthiah,

    You should not have to call GetIdsOfNames. If you want to make late
    bound calls, you should use reflection instead. What exactly are you trying
    to do? Are you indeed trying to make late bound calls?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Muthiah Samy" <muthiahr@aztec .soft.net> wrote in message
    news:4bae3b30.0 401200638.19e52 887@posting.goo gle.com...[color=blue]
    > Hi All,
    >
    > I am trying to call COM Component in .NET using PInvoke.
    >
    > In the following scenario, ( I am getting an exception called SEH -
    > External component has thrown an exception)
    >
    >
    > UnManaged Code
    > ---------------
    > virtual HRESULT IDispatch::GetI DSOfNames(const IID & riid, LPWSTR *
    > rgizNames, UINT CNames, LCID lcid, DISPID *rgDispID)
    >
    >
    > Managed Code (I have rewritten)
    >
    > ------------
    >
    > int GetIDsOfNames ([In] System.Guid guid, ref System.String[]
    > rgNames,[In] System.UInt32 cNames, [In] System.UInt32 lcid,
    >
    > [Out] out long[] dispID);
    >
    >
    > Public Test()
    > {
    >
    > AXIDispatch pIScriptDispatc h;
    > String[] wszScriptFuncti ons = new String[1];
    > wszScriptFuncti ons[0] = "entryMetho d";
    > long[] dispIDFunctions = new long[1];
    >
    > pIScriptHost.Ge tScriptDispatch (out pIScriptDispatc h);
    > IntPtr p = Marshal.GetIDis patchForObject( pIScriptHost);
    > IntPtr ppv;
    > Marshal.QueryIn terface(p,ref diug,out ppv);
    > pIScriptDispatc h = (AXUtil.AXIDisp atch)Marshal.Ge tObjectForIUnkn own(ppv);
    >
    > try
    > {
    > pIScriptDispatc h.GetIDsOfNames (guid,ref wszScriptFuncti ons, 1,
    > 1033, out dispIDFunctions );
    > }
    > catch (Exception ex)
    > {
    > Console.WriteLi ne (ex.ToString ());
    > }
    >
    > }
    >
    > If I execute Test() I will be getting the following Exception for
    > Invoking "GetIDsOfNames( ....)"
    >
    > System.Runtime. InteropServices .SEHException: External component has
    > thrown an exception.
    >
    >
    >
    > What could be the reason to get this kind exeception, I don't know
    > what to do in order to handle it error. Could anyone
    >
    > kindly help me to solve ? I will greatly appreciate.
    >
    > Thanks & Regards
    > R. Muthiah Samy[/color]


    Comment

    Working...