473,378 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Mixture of Managed and Unmanaged

In my current project (my first project using vc w/ managed extensions), I'm
directly #using <mscorlib.dll>, so it's necessary for me to use the __nogc
and __gc constructs when defining classes or structs.

The concept seems simple... some classes are managed, some aren't. I'm just
wondering if there are any major caveats here... anything I need to take
into consideration or keep an eye on.

I'm only using managed extensions so I can harness easy GUI creation... in
order words, no MFC or direct WinAPI stuff. But in terms of logic, I'd like
to keep everything unmanaged.

Is it not as simple as it seems?

Thanks!

--
Bill Merrill
Lead Developer
Merchant Companion
http://www.merchantcompanion.com
Nov 17 '05 #1
2 1218
TOM
Hi Bill,

I enjoy using the maanged code, hope you will as well. Unmanaged code
has a couple of
things to watch for:

1) You are responsible for constructor (except default) and destructor
invocation for unmanaged
variables, the CLR takes care of lifetime management for managed objects.

2) The CLR can move managed objects (and thus pointers to them) at any
time [usually
during garbage collection]. Thus you cannot pass a pointer to a managed
object to your unmaanged
class - otherwise the pointer could go stale or worse and your unmanged code
will do [very] bad things.
You need to __pin the pointer before passing it to unmanaged code. The
compiler tries to help
you here by making casts to managed objects cause errors in unmanaged code.
PINned pointers
can be cast easily.

3) The #include files for VC7.x, Win32, and WinDDK have a lot of
conflicts, and really mess up a
lot of legacy code. My solution is to isolate unmanaged code to separate
files so that headers don't
cross between the files. You can declare a forward reference pointer to a
non-managed object from
within your managed code without the compiler complaining -- so that helps
reduce the #include
dependency problem.

-- Tom

"The unProfessional" <sp**@shitbits.com> wrote in message
news:qL********************@mpowercom.net...
In my current project (my first project using vc w/ managed extensions),
I'm
directly #using <mscorlib.dll>, so it's necessary for me to use the __nogc
and __gc constructs when defining classes or structs.

The concept seems simple... some classes are managed, some aren't. I'm
just
wondering if there are any major caveats here... anything I need to take
into consideration or keep an eye on.

I'm only using managed extensions so I can harness easy GUI creation... in
order words, no MFC or direct WinAPI stuff. But in terms of logic, I'd
like
to keep everything unmanaged.

Is it not as simple as it seems?

Thanks!

--
Bill Merrill
Lead Developer
Merchant Companion
http://www.merchantcompanion.com

Nov 17 '05 #2
The unProfessional wrote:
In my current project (my first project using vc w/ managed extensions), I'm
directly #using <mscorlib.dll>, so it's necessary for me to use the __nogc
and __gc constructs when defining classes or structs.

The concept seems simple... some classes are managed, some aren't. I'm just
wondering if there are any major caveats here... anything I need to take
into consideration or keep an eye on.

I'm only using managed extensions so I can harness easy GUI creation... in
order words, no MFC or direct WinAPI stuff. But in terms of logic, I'd like
to keep everything unmanaged.

Is it not as simple as it seems?

Thanks!


Yes it is as simple as it seems. This is the power of C++.NET.

Actually this is why I love .NET so much - C++.NET just makes it so
useable in a way which VB6 never ever got even close to.

C# is a great language too - I'd seriously consider writing most of your
app in C# and only use C++.NET to interface with native code (in an
assembly obviously).

David.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
1
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. ...
5
by: Chris Kiechel | last post by:
I am writing a .NET Windows application and it needs to perform DDE calls to a legacy system. I created a C++ unmanaged class that performs the actual DDE connection and communication. However,...
4
by: repstat | last post by:
Hi I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
2
by: Martin Zenkel | last post by:
Dear VS Team, using the Beta 2 of VS 2005 I've encontered the following problem. Let's assume threre are three Dll's, one unmanaged and two managed. In the unmanaged we put a simple unmanged...
3
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...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
25
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.