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 1 1655
Sparhawk wrote: 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 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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JC |
last post by:
How does garbage collection work in C# and VB.NET for data returned from COM
object? For example, a COM object written in C++ returns a SAFEARRAY to C#
or VB.NET, will this SAFEARRAY (mapped to type in C# or VB.NET) be garbage
collected? Similarily, if C# or VB.NET pass SAFEARRAY to the COM object via
COM method invocation, will this SAFEARRAY be garbage collected after the
call?
My guess to answers for both questions is yes. Thanks.
|
by: Jón Sveinsson |
last post by:
Hello everyone
I have been trying to read and write struct to binary
files, I'm using
to functions to convert the struct to bytes and bytes to
struct, I
always receive the following error
C:\Documents and Settings\jon.JONHS-LAP\My
Documents\Visual Studio
|
by: Gernold Schneider |
last post by:
I have a managed code function calling a unmanaged code
function which returns a "bool". Obviously the return value
is always "true", if i am not running the code in the debugger.
If i run the code in the debugger, everything works fine.
Is this a known bug?
Example:
|
by: Daniel Mori |
last post by:
Hi, Im hoping someone can give me some advice.
Im doing some development using VS Whidbey 2005 beta 1.
Im about to implement some highly time critical code related to a
managed collection of floats.
I basically require the fastest way to convert a managed array of
floats into an unmanaged array of floats.
As far as the managed collection is implemented, ive read that the
|
by: Ghost |
last post by:
Hi all, I wrote a program in C# and now I have to "translate" it i
visual C++ (MFC) using .NET, but I had a little problem:
*ERRORS*
error C3181: 'CTestDlg' : invalid operand for __typeof, expected
fully defined managed type
error C3363: 'void CTestDlg::BtnAboutClick(System::Object __g
*,System::EventArgs __gc *)' : cannot create a delegate handler fo
'System::EventHandler' from a non-member function or a member of a
| |
by: RedJoy |
last post by:
I am switching from VS2003 .NET to VS2005 and I receive the following
errorwhen compiling my project:
error C3821: 'File': managed type or function cannot be used in an unmanaged
function c:\...\DataBase.cpp
I looked at the knowledgebase:
http://msdn2.microsoft.com/en-us/library/4756a450.aspx and tried to fix the
problem from there but with little success.
|
by: Steve |
last post by:
I'm trying to call some unmanaged methods from a DLL. I did this awhile
ago, a couple years ago... I'm a little rusty. I will show you what I'm
dealing with:
<unmanaged function signature>
STATUS_T WINAPI MSP430_Initialize(CHAR* port, LONG* version);
</unmanaged function signature>
STATUS_T is a long (typedef long STATUS_T)
|
by: Duncan Smith |
last post by:
I have a VS2005 C++ MFC project which #imports a type library. The
goal is to introduce some managed code eventually, but for starters I
just need to set the /clr compiler option and build the project.
The type library is imported like so:
#import <LtipClient.tlbno_namespace named_guids
With the /clr switch on, I got lots of LNK2028 errors, so I added the
following directive to the top of each cpp source file
|
by: vijay.gandhi |
last post by:
Hi,
I am trying to convert some unmanaged code (C++) to managed code
(using C++/CLI).
1) One of the functions used returns a void* which I need to cast into
a handle of a managed object. Can somebody please tell me how.
Actually, the function that returns a void* is a part of a MFC class -
CPtrList, used in my unmanaged code. I was searching of its equivalent
|
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...
|
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: 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: 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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |