Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2004

Tip: Looking for answers? Try searching our database.

Only one type of Unmanaged code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sparhawk - 29 Nov 2004 15:00 GMT
Hi,

my company is going to migrate a large VC++ application to .NET to
make use of Windows Forms (the old class library is not updated any
more). We are not planning to migrate the rest of the code which works
well.

I understand the basic concept: our code is unmanaged, Windows Forms
is Managed and Unmanaged may not call Managed code. I read about
Wrappers, PInvoke, Runtime Callable Wrappers for COM and about It just
Works (IJW). But I still have some unsolved questions.

1. If I write a managed wrapper for an unmanaged class, I use a
pointer of the unmanaged class in my managed class. Doesn't that make
my Managed Class Unmanaged? In which cases are pointers allowed in
Managed code?

2. If I compile my old code with the /clr switch (IJW) I get MSIL
code, which is unmanaged. Does this mean, that there are two types of
unmanaged code, one native (cpu dependent code), one MSIL? This would
probably answer 4. & 5. as well.

3. Is the __nogc completely optional? It seems that every class
without __gc gets an __nogc implicitly.

4. What does #pragma unmanaged do? Does it have the same effect as
writing __nogc?

5. I can't call Managed Code from Unmanaged Code. But (in the easy
examples) if I have an unmanaged function and a managed function in
the same file, the unmanaged one may call the managed one. Is there a
rule in which cases Unmanaged may call Managed?

6. Our code uses multiple inheritance. Does that mean that it can't be
compiled as Unmanaged MSIL (using IJW, /clr)?

Thanks in advance, those questions keep bugging me.
   Kay
Carl Daniel [VC++ MVP] - 29 Nov 2004 16:12 GMT
> Hi,
>
> my company is going to migrate a large VC++ application to .NET to
> make use of Windows Forms (the old class library is not updated any
> more). We are not planning to migrate the rest of the code which works
> well.

If your program has an elaborate UI built on MFC, you might consider waiting
for VC8, which will have seamless interop between MFC and Windows forms
(e.g. simple hosting of a WinForms control within an MFC window and
vice-versa).

> I understand the basic concept: our code is unmanaged, Windows Forms
> is Managed and Unmanaged may not call Managed code. I read about
[quoted text clipped - 5 lines]
> my Managed Class Unmanaged? In which cases are pointers allowed in
> Managed code?

No, it doesn't make your class unmanaged.  It's a managed class with data
member of value-type (pointer) that happens to point to some unmanaged
memory.  As far as the CLR is concerned, it's no different than a 32 bit
integer.

> 2. If I compile my old code with the /clr switch (IJW) I get MSIL
> code, which is unmanaged. Does this mean, that there are two types of
> unmanaged code, one native (cpu dependent code), one MSIL? This would
> probably answer 4. & 5. as well.

If you compile existing C++ code with /clr you get managed code that
manipulates unmanaged data.

> 3. Is the __nogc completely optional? It seems that every class
> without __gc gets an __nogc implicitly.

That depends on whether you're operating under the influence of #pragma
managed (the default with /clr) or #pragma unmanaged.

> 4. What does #pragma unmanaged do? Does it have the same effect as
> writing __nogc?

Yes.  It causes everything not explicitly marked __gc to be implicitly
marked __nogc.

> 5. I can't call Managed Code from Unmanaged Code. But (in the easy
> examples) if I have an unmanaged function and a managed function in
> the same file, the unmanaged one may call the managed one. Is there a
> rule in which cases Unmanaged may call Managed?

You just named one.  That's the principal behind IJW - within an MC++
compiland, managed can call unmanaged and vice-versa and It Just Works.

> 6. Our code uses multiple inheritance. Does that mean that it can't be
> compiled as Unmanaged MSIL (using IJW, /clr)?

No.  It means that your inheritance hierarchy cannot be expressed in terms
of the CLR concept of inheritance.  Normal C++ code (lacking any __gc
qualifiers), when compiled with /CLR exposes neither inheritance nor even
classes to the CLR.  It's simply code targeting a different "machine
language" (the CLI) that has complete control over the data it references.

-cd

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.