从C#访问OCX库时发生“灾难性故障”
||
我目前正在尝试使用C#应用程序中的第三方DLL。我已经注册了DLL,并将其添加为COM组件列表中的引用。据我了解,这应该创建必要的互操作类以从C#访问此DLL。
尝试从DLL中调用任何方法时,出现以下异常:
System.Runtime.InteropServices.COMException was unhandled
Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Source=mscorlib
ErrorCode=-2147418113
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at OCXDLL._OCXDLL.MyMethod(Int32 param0, String param1, String param2, String param3, Int32 param4)
at MyApplication.Program.Main(String[] args) in C:\\MyApplication\\Program.cs:line 29
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
我用来调用该库的代码:-
using OCXDLL;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
OCXDLL libObj = new OCXDLL();
libObj.MyMethod(....);
}
}
}
请注意,这不是ActiveX控件(为此,我已经看到了许多解决此问题的解决方案)。
有人对我要去哪里出错有任何想法吗?
谢谢
没有找到相关结果
已邀请:
2 个回复
诞胃
如您所见,我试图从主对象创建一个实例并调用其方法,但是这样做不正确! 创建MFC项目时,将自动生成两个接口,并使用它们来声明用于入站或出站调用的方法。一种带有_D前缀(在我的情况下为_DxPKTB),另一种带有_D前缀和事件后缀(_DxPKTBEvents)。 当您想在c#中调用Activex方法时,必须从其接口创建一个实例,然后调用该方法,而不是直接调用基础对象的方法!
这个技巧对我有用。希望对您也有用...
粟痢凰副