473,941 Members | 11,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1250
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******** ************@mp owercom.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
741
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 managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method (defined on a 'Global Functions' class) in the generated assembly with an export name of the form...
1
2137
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. The guts will remain in unmanaged c++. So I need to write public managed c++ wrapper classes for the couple of interfaces the unmanaged stuff needs to expose for the GUI. Questions:
5
3634
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, I need .NET to instantiate this object and somehow allow the this object to callback to .NET. So, my question is: 1. How can a managed class instantiate and unmanaged class?
4
7192
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 functions in a C++ DLL. My first question is, if I insert a C++ project into my C# solution, how will VS.NET know that I want it to be unmanaged code? I intend to be calling the DLLs functions using DllImport. I've heard that you can have unmanaged...
3
3521
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
2334
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 struct "A" which is exported in the usual way. The first managed assembly defines a managed class "B" using the unmanaged class "A" defined in the unmanaged Dll. This class "B" has got a public
3
2788
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.
9
3137
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
25
3040
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 MyClass:IDisposable
0
10134
marktang
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9965
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,...
0
11530
Oralloy
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...
0
11117
jinu1996
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...
1
11297
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,...
1
8218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7390
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();...
0
6080
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...
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.