Connecting Tech Pros Worldwide Help | Site Map

C# Wrapper into unmanged code

Jason
Guest
 
Posts: n/a
#1: Dec 8 '07
Hello

I've got a DLL that is written in C++ and I want to create a C# wrapper for
it, instead of using Pinvoke. I know this can be done, but I'm not sure how
to go about this. I've got VS 2005 and I've been looking on the net, but
not alot of clear definitions out there. For now, until I get he hang of it,
my c++ DLL is pretty basic, as it only has functions that take in and return
integers.

Can anyone provide an example, or point to a good place on the web?

Thanks


=?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=
Guest
 
Posts: n/a
#2: Dec 8 '07

re: C# Wrapper into unmanged code


You'll have to use PInvoke to get at the C++ code from your C# wrapper.

If your C++ Dll has C++ classes in it, you won't be able to PInvoke them.

I suggest you write a managed wrapper in C++/CLI. C++/CLI uses C++ Interop
(or Implicit PInvoke) and wouldn't require that you manually PInvoke. This
is especially useful if you want to use a native C++ class in C#.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"Jason" wrote:
Quote:
Hello
>
I've got a DLL that is written in C++ and I want to create a C# wrapper for
it, instead of using Pinvoke. I know this can be done, but I'm not sure how
to go about this. I've got VS 2005 and I've been looking on the net, but
not alot of clear definitions out there. For now, until I get he hang of it,
my c++ DLL is pretty basic, as it only has functions that take in and return
integers.
>
Can anyone provide an example, or point to a good place on the web?
>
Thanks
>
>
>
Jason
Guest
 
Posts: n/a
#3: Dec 9 '07

re: C# Wrapper into unmanged code


Thats what I was think I would need to do, write a managed wrapper in C++
but I'm not sure how to accomplisj that. Is there a good example that you
can point out?
"Peter Ritchie [C# MVP]" <PRSoCo@newsgroups.nospamwrote in message
news:31993116-7FE7-4107-B784-034615DFCCA3@microsoft.com...
Quote:
You'll have to use PInvoke to get at the C++ code from your C# wrapper.
>
If your C++ Dll has C++ classes in it, you won't be able to PInvoke them.
>
I suggest you write a managed wrapper in C++/CLI. C++/CLI uses C++
Interop
(or Implicit PInvoke) and wouldn't require that you manually PInvoke.
This
is especially useful if you want to use a native C++ class in C#.
>
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
>
>
"Jason" wrote:
>
Quote:
>Hello
>>
>I've got a DLL that is written in C++ and I want to create a C# wrapper
>for
>it, instead of using Pinvoke. I know this can be done, but I'm not sure
>how
>to go about this. I've got VS 2005 and I've been looking on the net, but
>not alot of clear definitions out there. For now, until I get he hang of
>it,
>my c++ DLL is pretty basic, as it only has functions that take in and
>return
>integers.
>>
>Can anyone provide an example, or point to a good place on the web?
>>
>Thanks
>>
>>
>>

Leon Lambert
Guest
 
Posts: n/a
#4: Dec 10 '07

re: C# Wrapper into unmanged code


I use IJW to interface my C# applications to unmanaged C++ DLLS. It
involves making a managed C++ interface assembly though. Doing it this
way the C++ can expose entire classes and their methods and not just C
style methods. I find it really easy to do. Following is a link that
helps to understand how to use IJW.
http://www.codeproject.com/KB/mcpp/ijw_unmanaged.aspx

Hope this helps
Leon Lambert

Jason wrote:
Quote:
Hello
>
I've got a DLL that is written in C++ and I want to create a C# wrapper for
it, instead of using Pinvoke. I know this can be done, but I'm not sure how
to go about this. I've got VS 2005 and I've been looking on the net, but
not alot of clear definitions out there. For now, until I get he hang of it,
my c++ DLL is pretty basic, as it only has functions that take in and return
integers.
>
Can anyone provide an example, or point to a good place on the web?
>
Thanks
>
>
Closed Thread