472,796 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

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 5927
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roth | last post by:
I have an unmanaged C++ dll that exports 2 classes and a stl list. I've had no trouble writting wrapper classes around the two exported classes with managed C++, but one class wants a list of...
5
by: Anthony Evans | last post by:
Greetings I'm using VC++.NET to create a class library. The class library contains managed classes that wrap legacy unmanaged classes by the same name. I use regasm to register the DLL for...
3
by: _BNC | last post by:
I have an old C DLL that I want to access via C#. I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged C++ class, which is in turn wrapped in a Managed C++ class. Both these...
1
by: roni | last post by:
hi. i have gc class written in manged c++ , some of his data members are __nogc pointers for arrays,structs.. and in that gc class methods i call to the unmaganged dll i wrap . my...
3
by: gopal | last post by:
I am developing an application in CSharp - windows forms based, which copies the DLLs both unmanaged and managed DLLs from a shared folder and will overwrite the existing versions of managed &...
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
7
by: DaTurk | last post by:
Hi, I'm coding up an application that has a native c++ layer, asynchronously calling callback in a CLI layer. We originally did this with static inline methods in the CLI layer, but this...
0
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk...
8
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.