无法从C#调用COM DLL

时间:2012-06-27 14:28:36

标签: c# c++ com invoke

我试图使用来自C#(4.0)服务的COM调用C ++和C#DLL。 DLL已在同一服务器(win2003)上注册,并且当前正在使用COM从C ++服务调用而没有问题(超过100k次)。这些DLL公开了一个接口“ExecuteTransaction”,它接受两个参数。

当我尝试从C#调用它时,我看到了一系列不同的错误

COM DLL启动但错误输出:

- 0x800706be;The remote procedure call failed.;
8004d00a;[Microsoft][ODBC driver for Oracle]Failure enlisting in Resource Manager

然后C#服务将出错:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Operation aborted (Exception from HRESULT: 0x80000007)
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

另一个C ++ DLL只会挂起事件日志中的消息:

A MS DTC component has encountered an internal error. The process is being terminated. Error Specifics: A non-MS DTC XA Library threw an exception in function oerhms ntdll!KiFastSystemCallRet + 0x0 + 0xb837ce8

代码是

using System;
using System.Collections.Generic;
using System.Reflection;
using System.EnterpriseServices;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;

....
int orderId = 65827;
int datasetId = 119849;
object objBM = null;
System.Guid bmGuid = new Guid("{43AFB035-9CFF-11D3-859D-0008C729AAEA}");

Type objBMType = Type.GetTypeFromCLSID(bmGuid);
objBM = Activator.CreateInstance(objBMType);
object[] args = {orderId,datasetId};
object c = objBMType.InvokeMember("ExecuteTransaction", System.Reflection.BindingFlags.InvokeMethod, null, objBM, args);

调用C#COM + dll也会出现问题。 该服务将出错

System.Reflection.TargetInvocationException: Exception has been thrown by the target   of an invocation. ---> System.Runtime.InteropServices.COMException: The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

服务和dll都在同一台服务器上。我究竟做错了什么?我错过了使用声明吗?我查看了WEB上的示例并尝试了但是所有人都给出了相同的错误?有趣的是,DLL在内部启动但在内部失败,就像我调用它们的方式不正确一样

0 个答案:

没有答案