468,512 Members | 1,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Wrapping Unmanaged c++ classes in Managed C++

Hi,
I am trying to expose the functionality of an unmanaged
C++ class to the other languages available in the .NET
Framework. I have decided to do this by wrapping the
unmanaged C++ class in a managed one. I have taken a look
at following sample code on how to do this.

http://longhorn.msdn.microsoft.com/l...vcmg_appendixs
amplecode.aspx

I have compiled this sample code and it all works fine.
Except that after I add a reference to the resulting
assembly in my C# project and look at it in the Object
Browser I can see all of the unmanaged functionality that
is exposed in the #included atlsecurity.h header file. How
can I hide these definitions so that c# cannot see
them ..after all it cannot use them. I would like only the
managed c++ wrapper class to be exposed.

This is not just an aesthetic issue. For instance if I
reference another assembly (which I don't have control of)
that has a class that is of the same name as one of the
unmanaged classes exposed above then the c# compiler
issues a warning (ambiguous name) when compiling it and
depending on the order in which the references were added
it may attempt to use the unmanaged class rather than the
other managed one which I want to use. A similar situation
in VB.NET results in a compiler error (ambiguous name) so
the application cannot be built at all.

I only used the above sample code to demonstrate my
problem. I have infact implemented my wrapper class and in
it's implementation it wraps a number of unmanaged c++
classes resulting in the contents of a lot of unmanaged
header files to be exposed in the resulting managed
assembly. So again my question is how can I hide the
contents of these unmanaged header files and only expose
my managed classes in my managed assembly??

Any help is greatly appreciated.
Cheers,
Paul

Paul Kenny
IONA Technologies
pa********@nospam.iona.com
Nov 16 '05 #1
2 5734
Paul Kenny wrote:
Hi,
I am trying to expose the functionality of an unmanaged
C++ class to the other languages available in the .NET
Framework. I have decided to do this by wrapping the
unmanaged C++ class in a managed one. I have taken a look
at following sample code on how to do this.

http://longhorn.msdn.microsoft.com/l...vcmg_appendixs
amplecode.aspx

I have compiled this sample code and it all works fine.
Except that after I add a reference to the resulting
assembly in my C# project and look at it in the Object
Browser I can see all of the unmanaged functionality that
is exposed in the #included atlsecurity.h header file. How
can I hide these definitions so that c# cannot see
them ..after all it cannot use them. I would like only the
managed c++ wrapper class to be exposed.
Did you try using #pragma unmanaged for your unmanaged code ?

This is not just an aesthetic issue. For instance if I
reference another assembly (which I don't have control of)
that has a class that is of the same name as one of the
unmanaged classes exposed above then the c# compiler
issues a warning (ambiguous name) when compiling it and
depending on the order in which the references were added
it may attempt to use the unmanaged class rather than the
other managed one which I want to use. A similar situation
in VB.NET results in a compiler error (ambiguous name) so
the application cannot be built at all.


Namespaces exist so that your above scenario need never happen,
Nov 16 '05 #2
>Did you try using #pragma unmanaged for your unmanaged
code ?

Yes, I tried that but it didn't make any difference.
Namespaces exist so that your above scenario need never happen

I have no control over either the unmanaged c++ class that
I am trying to wrap or .NET assembly that I am trying to
import (which clashes with the some of the unmanaged types
in the unmanaged c++ class that I am trying to wrap.)

I still don't understand why these unmanaged types are
being exposed at all.
-----Original Message-----
Paul Kenny wrote:
Hi,
I am trying to expose the functionality of an unmanaged
C++ class to the other languages available in the .NET
Framework. I have decided to do this by wrapping the
unmanaged C++ class in a managed one. I have taken a look at following sample code on how to do this.

http://longhorn.msdn.microsoft.com/l...vcmg_appendixs amplecode.aspx

I have compiled this sample code and it all works fine.
Except that after I add a reference to the resulting
assembly in my C# project and look at it in the Object
Browser I can see all of the unmanaged functionality that is exposed in the #included atlsecurity.h header file. How can I hide these definitions so that c# cannot see
them ..after all it cannot use them. I would like only the managed c++ wrapper class to be exposed.
Did you try using #pragma unmanaged for your unmanaged

code ?

This is not just an aesthetic issue. For instance if I
reference another assembly (which I don't have control of) that has a class that is of the same name as one of the
unmanaged classes exposed above then the c# compiler
issues a warning (ambiguous name) when compiling it and
depending on the order in which the references were added it may attempt to use the unmanaged class rather than the other managed one which I want to use. A similar situation in VB.NET results in a compiler error (ambiguous name) so the application cannot be built at all.
Namespaces exist so that your above scenario need never

happen,

.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Roth | last post: by
5 posts views Thread by Anthony Evans | last post: by
1 post views Thread by roni | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.