从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控件(为此,我已经看到了许多解决此问题的解决方案)。 有人对我要去哪里出错有任何想法吗? 谢谢     
已邀请:
为我解决! 我有同样的问题大约两个星期! 我试图在C#中从ocx创建一个实例。该对象已成功创建,但是我无法通过该死的Catastrophic Exception调用其方法。
 xPKTBLib.xPKTB p = new xPKTBLib.xPKTB()
如您所见,我试图从主对象创建一个实例并调用其方法,但是这样做不正确! 创建MFC项目时,将自动生成两个接口,并使用它们来声明用于入站或出站调用的方法。一种带有_D前缀(在我的情况下为_DxPKTB),另一种带有_D前缀和事件后缀(_DxPKTBEvents)。 当您想在c#中调用Activex方法时,必须从其接口创建一个实例,然后调用该方法,而不是直接调用基础对象的方法!
  xPKTBLib._DxPKTB p = new xPKTBLib.xPKTB();
这个技巧对我有用。希望对您也有用...     
视觉工作室 单击工具->选项->调试 仅禁用我的代码(仅受管理) 在此警告下如果没有用户代码启动 对我来说是工作。     

要回复问题请先登录注册