none
64-bit ActiveX Interop Problem RRS feed

  • Question

  • Our sister company wrote an ActiveX component for interfacing to a device that they(we) sell.  I have developed a VS2008 C# interface to the OCX by placing their COM object on a windows form then communicating through the generated interop.  But this is not working when I try to run the application on Win7 64-bit.  When I try to create the form which in turn loads the OCX, I get the following error:

    COMException was caught.  Class not registered (Exception from HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))

    The problem is not that the component is not registered.  I can see that the OCX is properly registered in the registry.  If I run their application it works fine with the registered OCX.

    I am able to debug the OCX.  I can see the constructor called on a 32-bit OS.  But the constructor is never called on a 64-bit OS.  There appears to be something wrong inside of the AxInterop. 

    I also tried regenerating the AxInterop in the development system running on a 64-bit OS.  I deleted and readded the component from the form.  But this did not change the problem.

    I am now at a complete loss as to where to look next.

    Wednesday, August 25, 2010 4:53 PM

Answers

  • The OCX talks to a hardware device through a driver that someone else wrote.  There is a problem with the device driver that I cannot solve.  We have decided to abandon this part of the project.  I cannot spend any more time on this problem.  Thanks for trying.

    • Marked as answer by megabitee Wednesday, September 1, 2010 1:19 PM
    Wednesday, September 1, 2010 1:18 PM

All replies

  • Hi,

    May I know the Platform Target of your C# application, x86, x64 or AnyCPU. by default, the Platform Target option is AnyCPU, which means your C# application will run as 64bit process on 64bit OS, if, at same time, the OCX is 32bit, you may get the REGDB_E_CLASSNOTREG exception.

    Change the Platform Target to x86 may fix this issue.

     


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, August 26, 2010 5:55 AM
  • Yes, we thought of that.  Changed the Platform Target of the C# assembly to x86.  But we get the same error.

    Thursday, August 26, 2010 2:52 PM
  •  

    Could you please use Process Monitor to detect the registry activities of your application, and send the log file to me? My mail address is v-eryang@microsoft.com.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 27, 2010 10:15 AM
  • Good Idea!  Log file sent.

    It appears that we are trying to open the wrong key. I see RegOpenKey for the key

        HKCR\Wow6432Node\CLSID\{28DC9B13-F17F-49C7-9B95-66E8458D3928}\InprocHandler32

    But...the actual registry key is InprocServer32.  Why is it looking for InprocHandler32?

    Running the same code on XP 32-bit, we read both InprocServer32 and InprocHandler32. 

    System.Runtime.InteropServices.COMException was caught
      Message="Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
      Source="System.Windows.Forms"
      ErrorCode=-2147221164
      StackTrace:
           at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
           at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
           at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
           at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
           at System.Windows.Forms.AxHost.CreateInstance()
           at System.Windows.Forms.AxHost.GetOcxCreate()
           at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
           at System.Windows.Forms.AxHost.CreateHandle()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.AxHost.EndInit()
           at Ophir.PowerMeter.Pulsar.OphirFastXLibContainer.InitializeComponent() in C:\Version5\LBA\Source\Ophir.PowerMeter.Pulsar\OphirFastXLibContainer.designer.cs:line 54
           at Ophir.PowerMeter.Pulsar.OphirFastXLibContainer..ctor() in C:\Version5\LBA\Source\Ophir.PowerMeter.Pulsar\OphirFastXLibContainer.cs:line 16
           at Ophir.PowerMeter.Pulsar.OphirFastX.STAThread() in C:\Version5\LBA\Source\Ophir.PowerMeter.Pulsar\OphirFastX.cs:line 131
      InnerException:

    • Edited by megabitee Friday, August 27, 2010 4:12 PM new info
    Friday, August 27, 2010 2:03 PM
  •  

    Hi,

     

    Could you please manually check whether the HKCR\Wow6432Node\CLSID\{28DC9B13-F17F-49C7-9B95-66E8458D3928} contains InprocServer32 node?

     

    By the way, there is a BUFFER TOO SMALL  error when your process access HKCR\Wow6432Node\CLSID\{28DC9B13-F17F-49C7-9B95-66E8458D3928} key, what's the default value of HKCR\Wow6432Node\CLSID\{28DC9B13-F17F-49C7-9B95-66E8458D3928} registry key?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, August 30, 2010 9:02 AM
  • Yes, the actual key is InprocServer32 - HKCR\Wow6432Node\CLSID\{28DC9B13-F17F-49C7-9B95-66E8458D3928}\InprocServer32 is created when the OCX is registered.

    I ran the same program on a 32-bit OS.  The OCX loaded OK.  Keys queried included LocalServer32 and InprocServer32.  I did not see any reference to InprocHandler32 on the 32-bit OS.

    BUFFER OVERFLOW

    1) My program is not making the queries directly.  From the stack trace you can see that my program is calling System.Windows.Forms.AxHost.EndInit() which eventually ends with System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance().  I assume CoCreateInstance is making the queries in an attempt to find and load the OCX.  The "Class not registered" exception is being thrown by System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance().

    2) Explained here - http://blogs.technet.com/b/markrussinovich/archive/2005/06/04/buffer-overflows-in-regmon-traces.aspx and here - http://blogs.technet.com/b/markrussinovich/archive/2005/05/17/buffer-overflows.aspx

    Monday, August 30, 2010 2:01 PM
  • Hi megabitee,

    I still cannot reproduce this issue, could you please generate a small repro sample and send it to me? my mail address is v-eryang@microsoft.com


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 31, 2010 10:13 AM
  • A "small" repro is not possible.
    Tuesday, August 31, 2010 1:15 PM
  • Could you send me a full sample?
    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, September 1, 2010 1:35 AM
  • The OCX talks to a hardware device through a driver that someone else wrote.  There is a problem with the device driver that I cannot solve.  We have decided to abandon this part of the project.  I cannot spend any more time on this problem.  Thanks for trying.

    • Marked as answer by megabitee Wednesday, September 1, 2010 1:19 PM
    Wednesday, September 1, 2010 1:18 PM
  • Has there been any further development on this problem?  I appear to have run into the same thing myself, and I would be interested in any effective workarounds.  I'd be willing to try to help reproduce the problem, but in order to do so, I'll need a COM dll to test with---the one that gives me problems in my production code is a third party library.
    Wednesday, March 30, 2011 7:08 PM