开发者

"Catastrophic failure" when accessing an OCX library from C#

I'm currently trying to use a third-party DLL from my C# application. I've registered the DLL and added it as a reference from the list of COM component. As I understand, this should create the necessary interop classes to access this DLL from C#.

On attempting to call any methods from within the DLL I get the following exception:-

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: 

And the code I'm using to call the library:-

using OCXDLL;

namespace MyApplication
{
 class Program
 {
  static void Main(string[] args)
  {
   OCXDLL libObj = new OCXDLL();
   libObj.MyMethod(....); 
  }
 }
}

Note that this is not an ActiveX control (for which I have seen a number of solutions to f开发者_StackOverflow中文版ix this problem).

Does anyone have any ideas as to where I'm going wrong?

Thanks


Solved For Me!

I had the same problem for about two weeks!!!

I was trying to create an instance from my ocx in c#. the object was successfully created but I was unable to call its methods with the damn Catastrophic Exception.

 xPKTBLib.xPKTB p = new xPKTBLib.xPKTB()

As you see I was trying to create an instance from the main object and call its methods but its Not the right thing to do! When you create a MFC project, two interfaces are generated automatically and you use them to declare your methods for inbound or outbound calls. One with _D prefix (in my case as _DxPKTB) and one with _D prefix and Events post-fix (_DxPKTBEvents).

When you want to call the Activex methods in c# you have to create an instance from it's interface and then call the methods instead of calling the base object's methods directly!

  xPKTBLib._DxPKTB p = new xPKTBLib.xPKTB();

this trick worked for me. Hope to be useful for you too...


Visual Studio

Click on TOOLs->OPTIONS->DEBUGGING

Disable just my code(Managed only)

under this Warn if no user code on launch

It's work for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜