Click to See Complete Forum and Search --> : Using OCX in C#
mhz_orcl
Aug 9th, 2005, 01:40 AM
Hello Expoerts...
I can build and use ocx in visual basic 6. OCX made by visual basic6 can be use in C# form? Plz help me for this purpose.
jmcilhinney
Aug 9th, 2005, 02:38 AM
You can add your ActiveX controls and COM components to the Toolbox by right-clicking and selecting Add/Remove Items. If your OCX file is not listed on the COM Components tab you can press the Browse button and navigate to it. You then check the objects you want to include in the Toolbox and press OK. You can then add your controls to a form like you would any other, which will add the required references to yuor project automatically. I've never developed for COM or ActiveX myself so I'm not sure, but I would imagine that you would have to register the controls in order to use them.
MrPolite
Aug 9th, 2005, 02:39 AM
totally not sure about what I'm saying but try this
right click somewhere on the Toolbar and click on Add/Remove Items
click on the COM Components tab and then browse for your OCX
maybe that'd work?:D
edit: ah 1 minute too late:D
mhz_orcl
Aug 9th, 2005, 02:44 AM
jmcilhinney and MrPolite
My special Thanks Goes to you. I can add OCX file C# form. My question was OCX which i made in VB will work in C# perfectly?
jmcilhinney
Aug 9th, 2005, 02:55 AM
C# cares nothing of the language used to create the classes it uses. It only cares about the interface that is exposed to it. In short, yes.
mhz_orcl
Aug 9th, 2005, 03:10 AM
jmcilhinney ....Thanksyou Very Much For ur Quick Reply.Take care
mhz_orcl
Aug 9th, 2005, 03:13 AM
jmcilhinney ....Thankyou Very Much For ur Quick Reply.Take care
MrPolite
Aug 9th, 2005, 01:37 PM
ok I have one question in the same context too...
I've heard it's a "bad" idea to use COM components anymore? why do they say that? is it because they fear your app would not be so portable if you use COM? (If so, who cares. There's only MONO for linux so far..:D)
Mike Hildner
Aug 9th, 2005, 02:19 PM
There's more complexity with using an ActiveX control from within C# (or VB.NET) that just using a .NET control.
When you add a reference to a COM object, Visual Studio automatically creates a Runtime Callable Wrapper (RCW). This (duh) is a wrapper around the COM object - your code actually calls the wrapper methods and not the COM object directly.
There have been some issues (well, one that I know of) with some ActiveX vendors where the automatically generated RCW did not work properly, so the vendor needed to create their own RCW and ship with the ActiveX control.
I'd prefer to use .NET components over COM objects if possible, as I've seen some things I don't like. Not sure if it's the architecture or just the nature of COM objects, but a lot of times there won't be superclasses/interfaces etc. Also, when trying to figure out the type of object at runtime, I've seen where sometimes the right type is returned, other times, it's named "__ComObject".
I have an app where the best solution was an ActiveX control, so I use COM objects if necessary, but I'd rather not if there's a good alternative.
Mike
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.