Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Using ActiveX control in C#

Using ActiveX control in C#

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studiocom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Big Trev
    wrote on last edited by
    #1

    Has any one had much luck with this. I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM. I add a reference to the DLL, then try to instantiate an object, I get the following error An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Catastrophic failure Has anyone any ideas. I have also tried this by just adding a reference to the original .ocx, and letting the IDE to the AXIMP for me. Same problem. Thanks

    S H 2 Replies Last reply
    0
    • B Big Trev

      Has any one had much luck with this. I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM. I add a reference to the DLL, then try to instantiate an object, I get the following error An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Catastrophic failure Has anyone any ideas. I have also tried this by just adding a reference to the original .ocx, and letting the IDE to the AXIMP for me. Same problem. Thanks

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      Big Trev wrote: I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM. These two actions are doing the opposite. If you intend to use an ActiveX control in your C# code, then use the IDE, Toolbox \ customize, and browse your ActiveX component. The ActiveX component will be preinteroped, so you don't need any manual call to aximp.exe (this works in most cases. There are gotcha though). When you drop the component into a form, you'll see whether it gets instantiated or not.


      RSS feed

      1 Reply Last reply
      0
      • B Big Trev

        Has any one had much luck with this. I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM. I add a reference to the DLL, then try to instantiate an object, I get the following error An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Catastrophic failure Has anyone any ideas. I have also tried this by just adding a reference to the original .ocx, and letting the IDE to the AXIMP for me. Same problem. Thanks

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        As Stephane said, just use the "Add Reference..." and select the COM tab. You almost have the right idea, though. Use aximp.exe to import an ActiveX control and create an interop assembly. DO NOT, however, register it! Regasm.exe is for registering assemblies that contain interop metadata, such as controls that act as ActiveX controls through a CCW (COM-Callable Wrapper). If you use Regasm.exe on the interop assembly generated by from the native ActiveX control, you've just overwritten the registry settings so that the interop assembly is now the target of the CLSID! Any application trying to instantiate your original ActiveX control is now instantiating (unknowingly in almost all cases) the control in the .NET assembly through a CCW. The interop assembly, however, is looking for the actual control and not finding it because it's finding itself! Now, I would hope (and don't remember off the top of my head) that regasm.exe checks to see if the assembly was imported from an ActiveX control. But it if isn't, you need to use "regasm.exe /u myassembly.dll" immediately, and then use "regsvr32.exe myactivex.ocx" to fix the registry problems that are most likely affecting you.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        B 1 Reply Last reply
        0
        • H Heath Stewart

          As Stephane said, just use the "Add Reference..." and select the COM tab. You almost have the right idea, though. Use aximp.exe to import an ActiveX control and create an interop assembly. DO NOT, however, register it! Regasm.exe is for registering assemblies that contain interop metadata, such as controls that act as ActiveX controls through a CCW (COM-Callable Wrapper). If you use Regasm.exe on the interop assembly generated by from the native ActiveX control, you've just overwritten the registry settings so that the interop assembly is now the target of the CLSID! Any application trying to instantiate your original ActiveX control is now instantiating (unknowingly in almost all cases) the control in the .NET assembly through a CCW. The interop assembly, however, is looking for the actual control and not finding it because it's finding itself! Now, I would hope (and don't remember off the top of my head) that regasm.exe checks to see if the assembly was imported from an ActiveX control. But it if isn't, you need to use "regasm.exe /u myassembly.dll" immediately, and then use "regsvr32.exe myactivex.ocx" to fix the registry problems that are most likely affecting you.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          B Offline
          B Offline
          Big Trev
          wrote on last edited by
          #4

          Thanks for the reply. I still can not get it working though. this is the code i am using to create the object. COMMSOCXLib.CommsOCXClass comm = new COMMSOCXLib.CommsOCXClass(); try { comm.Reset(); } catch (System.Runtime.InteropServices.COMException e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } And this is the error i catch. System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at COMMSOCXLib.CommsOCXClass.Reset()

          H 1 Reply Last reply
          0
          • B Big Trev

            Thanks for the reply. I still can not get it working though. this is the code i am using to create the object. COMMSOCXLib.CommsOCXClass comm = new COMMSOCXLib.CommsOCXClass(); try { comm.Reset(); } catch (System.Runtime.InteropServices.COMException e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } And this is the error i catch. System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at COMMSOCXLib.CommsOCXClass.Reset()

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            Did you unregister your interop assembly and re-register the actual ActiveX OCX? You might also re-install ActiveX control if it was packed in an installer, since the install might have written more registry entries. It seems as if the actual COM method (remember, the interop assembly is only a Runtime Callable Wrapper (RCW), in which calls are forwarded) is not being called because the forwarding method can't the object to call.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            B 1 Reply Last reply
            0
            • H Heath Stewart

              Did you unregister your interop assembly and re-register the actual ActiveX OCX? You might also re-install ActiveX control if it was packed in an installer, since the install might have written more registry entries. It seems as if the actual COM method (remember, the interop assembly is only a Runtime Callable Wrapper (RCW), in which calls are forwarded) is not being called because the forwarding method can't the object to call.

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              B Offline
              B Offline
              Big Trev
              wrote on last edited by
              #6

              Yep, i did a regasm /u on the interop assembly, and regsvr32 on the ocx. Still no joy. let me know if you fancy having a go with the ocx. I can mail it. it is only 100k. At the moment i an writing a DLL wrapper for the c api that also comes with the product. Thanks Trev

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups