COM interoperatability using PInvoke (SEH Exception)

M

Muthiah Samy

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::GetIDSOfNames(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 pIScriptDispatch;
String[] wszScriptFunctions = new String[1];
wszScriptFunctions[0] = "entryMethod";
long[] dispIDFunctions = new long[1];

pIScriptHost.GetScriptDispatch (out pIScriptDispatch);
IntPtr p = Marshal.GetIDispatchForObject(pIScriptHost);
IntPtr ppv;
Marshal.QueryInterface(p,ref diug,out ppv);
pIScriptDispatch = (AXUtil.AXIDispatch)Marshal.GetObjectForIUnknown(ppv);

try
{
pIScriptDispatch.GetIDsOfNames (guid,ref wszScriptFunctions, 1,
1033, out dispIDFunctions);
}
catch (Exception ex)
{
Console.WriteLine (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
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top