is the best way to wrap C functions with mananged C++ or C#?

T

teds

Hi,

As a newbie to .Net, I am interested in wrapping a library's C
functions to be accessible from .Net. These C functions take strings
as input and output parameters and may reallocate strings internally if
they need to be extended.

It appears that there are (at least) 2 ways to wrap my C functions.
The first way is to use managed C++ and create a .Net assembly. The
second way is to use C# to do the same thing.

My question is what are the advantages to either case assuming I now
C++ and C# equally well (or pooly)? Both would be accessible to any
..Net language and it would seem that I would be able to build a single
DLL if I used mananged C++ whereas I would need a separate DLL for my
C# wrapper. Are there other (dis)advantages I'm not considering?

Thanks,

Ted
 
C

Carl Daniel [VC++ MVP]

Hi,

As a newbie to .Net, I am interested in wrapping a library's C
functions to be accessible from .Net. These C functions take strings
as input and output parameters and may reallocate strings internally
if they need to be extended.

It appears that there are (at least) 2 ways to wrap my C functions.
The first way is to use managed C++ and create a .Net assembly. The
second way is to use C# to do the same thing.

My question is what are the advantages to either case assuming I now
C++ and C# equally well (or pooly)? Both would be accessible to any
.Net language and it would seem that I would be able to build a single
DLL if I used mananged C++ whereas I would need a separate DLL for my
C# wrapper. Are there other (dis)advantages I'm not considering?

You're probably better able to accomodate odd memory management requirements
using an MC++ wrapper, and the resulting solution should be slightly more
efficient due to differences between the IJW interop used by MC++ and the
PInvoke interop used by C#.

-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