How to add a VB ocx to a .NET VC++ project?

C

Carl Daniel [VC++ MVP]

Kueishiong said:
Is it possible to add a VB ocx to a .NET VC++ project?
If yes, how do I do it?

I'm assuming that by ".NET VC++ project" you mean that you have a managed
C++ (or C++/CLI) project. For these project types, use tlbimp.exe (from the
..NET framework SDK, also included with Visual Studio) to generate an
interop assembly that exposes the OCX as a .NET type.

You can also simply #import "path-to-your-ocx" to generate native wrappers
for the OCX, which you can then call from native or managed C++, but you
won't be able to get a verifiable managed image using this approach - if
that matters to you.

-cd
 
B

Ben Voigt [C++ MVP]

Carl Daniel said:
I'm assuming that by ".NET VC++ project" you mean that you have a managed
C++ (or C++/CLI) project. For these project types, use tlbimp.exe (from
the .NET framework SDK, also included with Visual Studio) to generate an
interop assembly that exposes the OCX as a .NET type.

You can also simply #import "path-to-your-ocx" to generate native wrappers
for the OCX, which you can then call from native or managed C++, but you
won't be able to get a verifiable managed image using this approach - if
that matters to you.

An OCX is a "control", not simply a COM class library, and I don't think the
#import option lets you host it in a Form. Or has someone found a way to do
that?
 
C

Carl Daniel [VC++ MVP]

Ben said:
"Carl Daniel [VC++ MVP]"
I'm assuming that by ".NET VC++ project" you mean that you have a
managed C++ (or C++/CLI) project. For these project types, use
tlbimp.exe (from the .NET framework SDK, also included with Visual
Studio) to generate an interop assembly that exposes the OCX as a
.NET type. You can also simply #import "path-to-your-ocx" to generate
native
wrappers for the OCX, which you can then call from native or managed
C++, but you won't be able to get a verifiable managed image using
this approach - if that matters to you.

An OCX is a "control", not simply a COM class library, and I don't
think the #import option lets you host it in a Form. Or has someone
found a way to do that?

My understanding is that technically, an OCX is nothing more than a AX
control with embedded TLB, while an AX control is a self-registering COM
object. But you're right, it's very likely that the OCX in question is
probably a GUI control.

No, #import won't let you host it in a form, that's for sure, but I think
that Winforms can host OCX controls already via tlbimp. I could well be
wrong about that - I've never done VB6 developmemnt and don't have any OCXs
lying about to experiment with.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top