I want to write a managed wrapper( kind of proxy) which will call into
unmanaged C++ code.
I've got a general idea and have read some articles on how to do it.
But I cannot find any information on some specific things..
for example, I have unmanaged class
class Foo
{
void SetData(std::ma p<std::string, std::stringsval ue);
};
I am not sure how I would represent this method in managed C++
especially when it comes to passing in/returning STL data structure
to/from unmanaged class.
Can someone please point me to any decent articles/documentation on
this?? I cannot find anything on microsoft site except how to use
managed String data type!
Your help will be much appreciated. Thanks 4 2445
>I want to write a managed wrapper( kind of proxy) which will call into
unmanaged C++ code.
I've got a general idea and have read some articles on how to do it.
But I cannot find any information on some specific things..
for example, I have unmanaged class
class Foo
{
void SetData(std::ma p<std::string, std::stringsval ue);
};
I am not sure how I would represent this method in managed C++
especially when it comes to passing in/returning STL data structure
to/from unmanaged class.
Can someone please point me to any decent articles/documentation on
this?? I cannot find anything on microsoft site except how to use
managed String data type!
AFAIK the STL components cannot be used directly in the .NET framework, so
you have to do the conversion between (for example) a hashtable and map.
Your proxy class could take a hashtable as input, and then create a new
stl::map and copy the contents of the hashtable into it for unmanaged use.
For output you'd do the same, but in the other direction: fill the hashtable
with copies of the contents of the stl::map.
The 1 exception is that you can use the stl::map as an IntPtr in .NET, as
long as you don't want to do anythin with it.
In that case you could return it from your unmanaged code as an IntPtr,
store the ptr in .NET code, and supply it back to your unmanaged code later.
--
Kind regards,
Bruno van Dooren br************* *********@hotma il.com
Remove only "_nos_pam"
I see so my managed wrapper method can take hasmap in as a param and
then I can use stl:map within the managed code to read from that
hashmap? I thought that managed code won't let me use the STL map even
though it is C++! I prefer this solution to the one with intptr as i am
not too familiar with that...
Thanks
Bruno van Dooren [MVP VC++] wrote:
I want to write a managed wrapper( kind of proxy) which will call into
unmanaged C++ code.
I've got a general idea and have read some articles on how to do it.
But I cannot find any information on some specific things..
for example, I have unmanaged class
class Foo
{
void SetData(std::ma p<std::string, std::stringsval ue);
};
I am not sure how I would represent this method in managed C++
especially when it comes to passing in/returning STL data structure
to/from unmanaged class.
Can someone please point me to any decent articles/documentation on
this?? I cannot find anything on microsoft site except how to use
managed String data type!
AFAIK the STL components cannot be used directly in the .NET framework, so
you have to do the conversion between (for example) a hashtable and map.
Your proxy class could take a hashtable as input, and then create a new
stl::map and copy the contents of the hashtable into it for unmanaged use.
For output you'd do the same, but in the other direction: fill the hashtable
with copies of the contents of the stl::map.
The 1 exception is that you can use the stl::map as an IntPtr in .NET, as
long as you don't want to do anythin with it.
In that case you could return it from your unmanaged code as an IntPtr,
store the ptr in .NET code, and supply it back to your unmanaged code later.
--
Kind regards,
Bruno van Dooren br************* *********@hotma il.com
Remove only "_nos_pam"
>I see so my managed wrapper method can take hasmap in as a param and
then I can use stl:map within the managed code to read from that
hashmap? I thought that managed code won't let me use the STL map even
though it is C++! I prefer this solution to the one with intptr as i am
not too familiar with that...
Maybe I was not clear enough.
There is no way that I know of to use stl::map as an argument in a method
that has to be used by other .NET languages.
But there is another option.
You create a proxy class that has a hashtable as an argument. A hashtable
and an STL map are functionally equivalent for most purposes.
inside your function call (managed C++) you can use both hashtable and
stl::map, since you are working in mixed mode.
So you create a new instance of an stl::map and fill it with the information
that is already contained in the .NET hashtable.
This means that the same information exists now as a managed hashtable, and
an unmanaged stl::map.
your unmanaged code can then invoke the original C++ class, and supply the
stl::map as an argument.
any changes to the stl::map during your invocation of the original class has
to be made to the hashtable as well afterwards.
There is a lot of overhead this way (because of all the copying) but there
is little that you can do about it.
--
Kind regards,
Bruno van Dooren br************* *********@hotma il.com
Remove only "_nos_pam"
Yes I see. Thanks!
Bruno van Dooren [MVP VC++] wrote:
I see so my managed wrapper method can take hasmap in as a param and
then I can use stl:map within the managed code to read from that
hashmap? I thought that managed code won't let me use the STL map even
though it is C++! I prefer this solution to the one with intptr as i am
not too familiar with that...
Maybe I was not clear enough.
There is no way that I know of to use stl::map as an argument in a method
that has to be used by other .NET languages.
But there is another option.
You create a proxy class that has a hashtable as an argument. A hashtable
and an STL map are functionally equivalent for most purposes.
inside your function call (managed C++) you can use both hashtable and
stl::map, since you are working in mixed mode.
So you create a new instance of an stl::map and fill it with the information
that is already contained in the .NET hashtable.
This means that the same information exists now as a managed hashtable, and
an unmanaged stl::map.
your unmanaged code can then invoke the original C++ class, and supply the
stl::map as an argument.
any changes to the stl::map during your invocation of the original class has
to be made to the hashtable as well afterwards.
There is a lot of overhead this way (because of all the copying) but there
is little that you can do about it.
--
Kind regards,
Bruno van Dooren br************* *********@hotma il.com
Remove only "_nos_pam"
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: kaalus |
last post by:
Hello
I have problem mixing managed and unmanaged C++ code in VS.NET 2003. I want to create a windows forms application which uses some C++ code that is incompatible with managed extensions (__fastcall etc.). I have tried disabling "compile as managed" option for these specific files, but it does not help: by trial and error I figured out that if there are any "references" in the project, IDE adds /FU switch with each of these references to...
|
by: Zak |
last post by:
It would be nice to have one DLL that contains both my managed and my
unmanaged functions. I would like to be able to use the unmanaged parts
from C++ without a .NET Framework dependency too.
Is this at all possible?
Currently, I have one DLL with a bunch of C functions that I use from
unmanaged C++ programs. I have another DLL with a bunch of .NET classes
that I use from C# and VB.NET. I would like to have all of this
combined in...
|
by: asanford |
last post by:
We use StackWalk(StackWalk64) from dbghelp.dll to walk our
callstacksas needed, using the various Sym* methods
(SymGetSymFromAddr, SymGetLineFromAddr) to resolve source file,
function name, and source line number for each frame. This works fine
for unmanaged code, but when we have a call stack that goes into or
through some managed code, we cannot resolve any info for the managed
frames - we can however, get all the information for the...
|
by: DotNetJunkies User |
last post by:
Background:
I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below:
Range r = new Range( 2, 2 );
r = new Cell( “Hello Mum” );
Range is a managed wrapper around an unmanaged range class. Vector is a managed wrapper around an unmanaged vector class. Cell is a managed wrapper around an unmanaged cell class.
Here r returns a managed Vector* and r accesses a particular Cell in the Vector.
|
by: tsmith |
last post by:
Hello,
Quick question: Can I mix managed C++ (forms and GUI stuff) with nonmanaged
C++ code (Direct3D). Note that I am not interested in managed DX (the C#
API). I still am writing C++ code, but would like to use the .NET GUI
library with managed C++, and unmanaged DX code. Is this possible and easy
to do?
| |
by: chuck rudolph |
last post by:
The project that I am on is going to require me to mix managed and unmanaged
code. I created a vc++ class library (.net) project bane TestLib.
I inserted the following test code in testLib.h. The code came from the MS
example on mixing managed and unmanaged code. When I build the project, I get
two unresolved external symbols on from the MClass Constructor and
Destructor. I'll guess I am missing a build switch. The doc says I need /clr...
|
by: Thorsten |
last post by:
HI
I'm a C# developer and unfortunately I have to write now some code in
managed and unmanaged C++. In this area I'm Newbie and therefore please
forgive me if this is a really simple question.
|
by: Sandy |
last post by:
I am confused about Unmanaged Code, How .Net Framework treate that code,
What is the use of that.
Thanks in advance
Sandeep Chitode
|
by: Ulrich Sprick |
last post by:
Hi,
I have to write a managed C++ wrapper around an existing, unmanaged C++
class. First tests suggested it should work, but after adding the complete
unmanaged code, I get the following linker errors:
LINK : error LNK2020: unresolved token (0A00001A) _CxxThrowException
LINK : error LNK2020: unresolved token (0A00001C) exception.__ctor
LINK : error LNK2020: unresolved token (0A00001E) exception.__dtor
LINK : error LNK2020: unresolved...
|
by: Jared Kail |
last post by:
I've never mixed managed and unmanaged C++ before, but I've done a lot
of "research" out on the web. Using some examples out there, I wrote this:
#using <mscorlib.dll>
using namespace System;
namespace ntMgdCls
{
__nogc class ntUnmgdCls
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |