accessing unmanaged C++ with VB or C#

B

Brett

We have an application completely written in C++ under visual studio v6. One
of our customers wants to use some of our existing components in his project
but doesn't know C++ and isn't interested in learning it. He does know C#
and VB though.

Whats the best option for us (ie. minimum work) to provide him with an API
that he can use in his own applications? I was originally considering a COM
interface, but looking into .NET, I'm wondering if we should just upgrade
the appropriate sections of code to "managed code" so he can use that from
one of his languages. Is this a big and difficult job in peoples experience?

Any advice is appreciated.

Thanks,
Brett.
 
B

Brett

Brett said:
We have an application completely written in C++ under visual studio v6. One
of our customers wants to use some of our existing components in his project
but doesn't know C++ and isn't interested in learning it. He does know C#
and VB though.

Whats the best option for us (ie. minimum work) to provide him with an API
that he can use in his own applications? I was originally considering a COM
interface, but looking into .NET, I'm wondering if we should just upgrade
the appropriate sections of code to "managed code" so he can use that from
one of his languages. Is this a big and difficult job in peoples experience?

Any advice is appreciated.

Thanks,
Brett.

I should also mention that the C++ program has significant custom graphics
support and has a large set of classes that are capable of controling a USB
device. There is no web interface or anything required.
 
R

Richard Grimes [MVP]

Brett said:
Whats the best option for us (ie. minimum work) to provide him with
an API that he can use in his own applications? I was originally
considering a COM interface, but looking into .NET, I'm wondering if
we should just upgrade the appropriate sections of code to "managed
code" so he can use that from one of his languages. Is this a big and
difficult job in peoples experience?

I assume you mean by using managed C++ to create wrapper classes. It's
not too difficult to do. Don't just compile your C++ with /clr because
that will make all the code compile to IL, except for code that won't
convert, in which case you'll have managed-unmanaged transitions. Its
better to compile your unmanaged code to a static lib, or a DLL and use
a simple wrapper class. That way you'll know that all of your library
will run as native code (as you intended and tested) and the
managed-unmanaged transitions will be where you expect them - in the
wrapper class.

Be aware of callback functions, because they will give another
managed-unmanaged transitions. You might want to pass large buffers into
your unmanaged code, in this case you can use the allocators in the
Marshal class; you could use .NET arrays, but in that case you'll have
to pin the array and that gets messy.

Richard
 

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