Using .Net (C#) ActiveX control within Builder 2009 (C++)

Hi,

We are moving one of our applications from Borland C++ Builder 4.5 to the latest builder 2009. There is also an activeX control in our application (Formule One spreadsheet) which is causing problems in this migration. As this control doesn't cover all our future needs, we are thinking about creating our own gridcontrol to use.

So I've been playing around and created an example control in .Net and exposed it as a COM object. When I try to add it to my C++ sample project, (Import component and create new package) and compile this package, I get the following error:
[BCC32 Error] GridControl_OCX.h(120): E2113 Virtual function '_fastcall TGridControl::GetHashCode()' conflicts with base class 'TObject'.

So made an even simplier activex control (copied from a website example), which is working fine when I use it in a C++ (MFC) project in Visual Studio, but I can't get it to work in CB2009. 

This is the code from the activex component:
using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;
using System.Reflection;


namespace Tester
{
    [Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
    public interface _Numbers
    {
        [DispId(1)]
        int GetDay();

        [DispId(2)]
        int GetMonth();

        [DispId(3)]
        int GetYear();

        [DispId(4)]
        int DayOfYear();
    }

    [Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("Tester.Numbers")]
    public class Numbers : _Numbers
    {
        public Numbers()
        {
            
        }

        public int GetDay()
        {
            return (DateTime.Today.Day);
        }

        public int GetMonth()
        {
            return (DateTime.Today.Month);
        }

        public int GetYear()
        {
            return (DateTime.Today.Year);
        }

        public int DayOfYear()
        {
            return (DateTime.Now.DayOfYear);
        }

        ///	<summary>
        ///	Register the class as a	control	and	set	it's CodeBase entry
        ///	</summary>
        ///	<param name="key">The registry key of the control</param>
        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            // Open the CLSID\{guid} key for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            // And create	the	'Control' key -	this allows	it to show up in
            // the ActiveX control container
            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            // Next create the CodeBase entry	- needed if	not	string named and GACced.
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            // Finally close the main	key
            k.Close();
        }

        ///	<summary>
        ///	Called to unregister the control
        ///	</summary>
        ///	<param name="key">Tke registry key</param>
        [ComUnregisterFunction()]
        public static void UnregisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            // Open	HKCR\CLSID\{guid} for write	access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            // Delete the 'Control'	key, but don't throw an	exception if it	does not exist
            k.DeleteSubKey("Control", false);

            // Next	open up	InprocServer32
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);

            // And delete the CodeBase key,	again not throwing if missing
            k.DeleteSubKey("CodeBase", false);

            // Finally close the main key
            k.Close();
        }
    }
}

Importing this in my 2009 project and build it, then I get the following error:
[BCC32 Error] Tester_OCX.h(120): E2113 Virtual function '_fastcall TNumbers::GetHashCode()' conflicts with base class 'TObject'

So... Isn't it possible to use an ActiveX control from .Net?? Or am I doing something wrong when inserting this control?

Thanks in advance,
Rutger
0
Rutger
3/26/2009 8:38:47 AM
embarcadero.cppbuilder.activex 257 articles. 0 followers. Follow

5 Replies
2208 Views

Similar Articles

[PageSpeed] 14
Get it on Google Play
Get it on Apple App Store

<Rutger Kars> wrote in message news:97159@forums.codegear.com...

> So I've been playing around and created an example control in .Net
> and exposed it as a COM object. When I try to add it to my C++
> sample project, (Import component and create new package) and
> compile this package, I get the following error:
> [BCC32 Error] GridControl_OCX.h(120): E2113 Virtual function
> '_fastcall TGridControl::GetHashCode()' conflicts with base class 
> 'TObject'.

..NET objects have Equals(), GetHashCode() and ToString() methods that are 
inherited from System.Object.  In 2009, the VCL's TObject class has new 
Equals(), GetHashCode() and ToString() methods that were introduced to 
mirror the .NET methods.  When you import an ActiveX control, a VCL wrapper 
is generated for it.  The TObject methods are conflicting with the .NET 
methods.  The importer has no way of knowing that the ActiveX control 
belongs to .NET so it can ignore the conflicting methods.

In your .NET class, you can try applying the ComVisible(false) attribute to 
those three methods so they are not exported to ActiveX.

-- 
Remy Lebeau (TeamB)
0
Remy
3/26/2009 5:34:53 PM
Thanks for your help! I already did found a way so those methods weren't in my exposed activeX. It's working now
0
Rutger
3/31/2009 8:56:01 AM
> {quote:title=Rutger Kars wrote:}{quote}
> Thanks for your help! I already did found a way so those methods weren't in my exposed activeX. It's working now

Could you explain how you did it?
0
Elena
5/6/2009 8:22:25 AM
> {quote:title=Elena Zamaraeva wrote:}{quote}
> > {quote:title=Rutger Kars wrote:}{quote}
> > Thanks for your help! I already did found a way so those methods weren't in my exposed activeX. It's working now
> 
> Could you explain how you did it?
Sorry for the late respone.

It can be achieved by adding [ClassInterface(ClassInterfaceType.None)] to your class definition, so only your explicit exposed methods are shown
0
Rutger
7/21/2009 9:30:39 AM
> {quote:title=Rutger Kars wrote:}{quote}
> > {quote:title=Elena Zamaraeva wrote:}{quote}
> > > {quote:title=Rutger Kars wrote:}{quote}
> > > Thanks for your help! I already did found a way so those methods weren't in my exposed activeX. It's working now
> > 
> > Could you explain how you did it?
> Sorry for the late respone.
> 
> It can be achieved by adding [ClassInterface(ClassInterfaceType.None)] to your class definition, so only your explicit exposed methods are shown

I compiled the code you submitted, registerd the dll by regasm, created a setup project (VS2005) to install the activex and all went fine; when I try to import the component in Delphi 2010 I can't see the activex in registered activex controls list. What I'm doing wrong? Thank you.
0
daniele
9/1/2009 8:35:20 AM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Properties of ActiveX Controls in C#.NET
Hi,A form has the list of all ActiveX controls on a machine. Now i need to get all the exposed property of any selected ActiveX control at run time and use them. Please reply if anybody has any idea. I need to do this in C#.NET. If any body has the matter in any other language like VB.NET etc, even then please share.Regards,Dheeraj Verma Hi,        Please reply to above [:'(]RegardsDheeraj...

ActiveX events in C++ Builder 2009
I developed my application with C + + Builder 2007. This application uses an ActiveX to display images from remote cameras. Now I would like to compile the same application with C + + Builder 2009. The compiling process works fine but when I launch the application I get several errors. Using breackpoint I noticed that the sequence of events generated by ActiveX in Builder in 2009 is different than Builder 2007. In particular, when I run the program some events are immediatly generated whereas in Bulder 20 07 the same events are generated by user actions. This is due to Activex or Builder 2...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

How to use a ActiveX Control in the C# code of a ASP Page
Hello,  I'm having an activex control i would like to use on our ASP pages. The control is a viewer on TM1. In the VS2005 i can add the code <Object....> but then when wanting to use the object in the aspx.cs code the object is unknown. I did enter the <Object> statement manually in the code, because even when adding the activex control to the toolbox it stays invisible in the toolbox (when doing this with a winform app it appears). Obviously i will be mixing some techniques and messing it up, but if anyone could help me getting started ...   Thx, Harry Hi, ...

My C#.NET ActiveX control is not receiving sufficient access!
My new C#.NET ActiveX control is not receiving enough access, and I am getting a registry "access denied" error. I know that I am not supposed to be accessing the registry from a non-trusted ActiveX control, so I added the website of the ActiveX to the "Trusted sites" zone in Internet Explorer. Now, the ActiveX control is not showing up at all, and instead just shows a little icon in the upper left corner. I am using Internet Explorer 8 Beta 2, and I tried running the website in compatibility mode as well. Why is it not showing up when in the "Trusted sites" z...

How to use method activeX control in PB (Newbie using ActiveX)
Hi all, This is the first time I'm using activeX in my application, does anyone can helpme with these problem. How to use method in activeX because I've got example that come with the ocx file only with VB6 and I don't know how to used it with PB7. ------------ Call ActiveX_name.CopyTable(filename As String,Creator As String,SDDI_plugin_name As String, CreateFlag As Integer, VersionMajor As Integer, VersionMinor As Integer) ------------ THX -- ebr ...

How Can I use the compliers used under Dev-C++ in C++ builder?
How Can I use the compliers (for instance GCC, ...) used under Dev-C++ in C++ builder? In my program,I used boost lambda expression under Dev-C++ due to the fact that C++ builder 2009 do not support such expression. But Dev-C++ do not support RAD(rapid application development). It is hard to establish the common graphic GUI under windows.So I want to use the compliers of Dev-C++ in C++ builder. And I do not know how to manage it. Where can I get the related materials or advices? Can any one with kindness help me? Il Tue, 11 Aug 2009 23:29:59 -0700, lserjt lserjt <> ha scritto:...

C++Builder 2006 stopped working after C++Builder 2009
Is there a way to key both IDEs (2006 & 2009) on the same computer while I complete software migration? Both compilers are installed on a Windows Vista Proffesional. Thanks, Roberto Hello, Roberto Meneghini wrote: > Is there a way to key both IDEs (2006 & 2009) on the same computer > while I complete software migration? yes, it works fine for me. What particular problem are you having? -- Moritz "Hey, it compiles! Ship it!" As soon as I launch the compiler, the following error message is displayed: "Exception EPackageRegistrationEx...

C# ActiveX Control
Help, I have created an ActiveX Control and embed it in a webpage. I can see the ActiveX UI in the webpage later, but when I try to call the function in the DLL there is nothing change, then I update the ActiveX Control to include a textbox to show what string I pass into the ActiveX, but when I tried to pass in some string into the textbox (by assigning a value to property "public string mywords" with get & set) using Javascript, also no success...  In fact I was refering to someone's code, I copied my function to the referal's code and it works! But it doesn't work on my code, wh...

ActiveX Control in C#
I want to pirnt some raw data on label printer attached to the client browser. I want to write one ActiveX Control in C# (also having some unmanaged code). And then i want to load it with the page in the client browser as we did in classic ASP and VB. Could anyone guide me to some good resource. Thanks, Riz hi! here is sample solution. It should help You. orzeh code less, think more! I am trying to call a C# ActiveX Control in aspx ASP.NET 2.0 page. The example you refered me was using older version. Any help? There is no such thing as a C# ActiveX control. Orze...

using arrow keys as tab to provide focus among the controls present in asp.net page using c#.net
 how can i use up,down,right,left arrow keys as tab to provide focus among the controls present in asp.net page using c#.net You can bind the keys of the keyboard to a function in the javascript http://www.vikramlakhotia.com/Binding_keyboard_shortcut_in_AspNet.aspx next in the function chnage the focus of the page to the next control available when u find the key pressed in the down arrowVikram www.vikramlakhotia.comPlease mark the answer if it helped you first of all tankq for guiding me  i dont want it to be binded to a particular control, it should be like tab index...

newbie - [c++ builder 5]
Hello experts, I'm trying to import an ActiveX Control in Borland C++ Builder 5.0 but after I install the generated package, no icon appears in the ActiveX palette tab. The ocx i'm trying to import is USB.OCX from Softmark (it controls a usb stepper motor controller board) I think it's because the control has no published properties and only has public functions but I'm not sure. I can use this control with no problem in excel vba applications but I would like to use it in builder instead. Here are the files that builder generates: USB_ActiveX_OCX.h {code} // **...

Migrating C++Builder ATL-Based ActiveX/COM Projects from 2009 to XE3 [Edit]
I have tried the second option from the section "ATL-Based C++ ActiveX/COM Projects" found in the RAD Studio: http://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2BBuilder_Uses_DAX_for_ActiveX_and_COM As other users have found in this forum thread: https://forums.embarcadero.com/message.jspa?messageID=443929 there are missing details from the RAD Studio documentation. I used this forum thread as my supplemental guide even though it is for 2007 to XE, but it appears the RAD Studio documentation on this topic is the same and the problems I initially encountered were the same. ...

Web resources about - Using .Net (C#) ActiveX control within Builder 2009 (C++) - embarcadero.cppbuilder.activex

ActiveX - Wikipedia, the free encyclopedia
... 1996 and is commonly used in its Windows operating system. In principle it is not dependent on Microsoft Windows, but in practice, most ActiveX ...

유자드 웹-무료 웹브라우저(Flash, ActiveX) on the App Store on iTunes
Get 유자드 웹-무료 웹브라우저(Flash, ActiveX) on the App Store. See screenshots and ratings, and read customer reviews.

Activex - ARN
The source for IT industry news, views and analysis across the channel, business and technology

IE8 to boost ActiveX security on Vista
ActiveX has long been regarded as a gaping hole through which spyware and …

Internet Explorer gets more secure will start blocking outdated ActiveX controls
... the computers of friends and family. Today, Microsoft announces that Internet Explorer is getting more secure by blocking outdated ActiveX controls. ...

ActiveX for Windows - Free downloads and reviews - CNET Download.com
The most downloaded ActiveX software, including PlayReady PC Runtime v1.3 (x64), PDF OCX, and PDF Maker DLL

Microsoft probing ActiveX attacks targeting Access feature
Vulnerability in ActiveX control for feature in Microsoft Access is being used for targeted but limited attacks, Microsoft says.

Microsoft nixes ActiveX add-on technology in new Edge browser
Microsoft's new Edge browser will discard two of the oldest browser technologies found in the aged Internet Explorer and replace them with add-ons ...

More issues with the Video ActiveX Control flaw workaround
The simple registry update to disable the buggy Video ActiveX Control is not as simple as it first appears.

Google's Native Client almost 'ready for takeoff,' ready to make ActiveX look visionary
We're almost there, almost to the release of the Native Client we first got wind of last May. It is, basically, a way to run native code within ...

Resources last updated: 2/14/2016 6:24:39 AM