By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

COM interoperatability using PInvoke (SEH Exception)

P: n/a
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(p pv);

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
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Muthiah Samy" <mu******@aztec.soft.net> wrote in message
news:4b**************************@posting.google.c om...
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(p pv);

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

Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.