473,395 Members | 1,678 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,395 software developers and data experts.

unmanaged & managed C++ questions

Ian
1. I want to be use mix unmanaged code with managed code. In particular,
the unmanaged code uses MFC CFile to perform file I/O. Can CFile be used
in unmanaged code that is mixes with managed code? I've tried this but
keep getting a system::exception is thrown with the message "External
component has thrown an exception" when the CFile instance is created.

2. How does the assignment operator check to see that the source and
destination objects are not the same in managed code? For example:

ref class A
{
A% operator=( A %a )
{
// if( this != &a ) // this line generates a compiler error.
{
...
}
}
};

The compile generates the error message "error C2446: '!=' : no conversion
from 'const CManaged' to 'CManaged ^const '" when the line "if( this !=
&a )" is uncommented. While this is to be expected, what is the proper way
to check if the source and destination objects are the same?

Ian
Oct 13 '06 #1
2 1256
Ian

"Ian" <Ia*******@yahXX.comwrote in message
news:nw********************@wagner.videotron.net.. .
1. I want to be use mix unmanaged code with managed code. In particular,
the unmanaged code uses MFC CFile to perform file I/O. Can CFile be used
in unmanaged code that is mixes with managed code? I've tried this but
keep getting a system::exception is thrown with the message "External
component has thrown an exception" when the CFile instance is created.
I'll post the answer for any other .NET newbies who might be trying to do
the same thing. MFC cannot be called from a .NET application (which is what
I was trying to do) but .NET can be called from an MFC application.

Ian


Oct 19 '06 #2

"Ian" <Ia*******@yahXX.comwrote in message
news:nw********************@wagner.videotron.net.. .
1. I want to be use mix unmanaged code with managed code. In particular,
the unmanaged code uses MFC CFile to perform file I/O. Can CFile be used
in unmanaged code that is mixes with managed code? I've tried this but
keep getting a system::exception is thrown with the message "External
component has thrown an exception" when the CFile instance is created.

2. How does the assignment operator check to see that the source and
destination objects are not the same in managed code? For example:

ref class A
{
A% operator=( A %a )
{
// if( this != &a ) // this line generates a compiler
error.
According to http://msdn2.microsoft.com/en-us/library/hxad2z4x.aspx, you
don't need an '&' at all.

http://msdn2.microsoft.com/en-us/library/9zekbcac.aspx adds some more
confusion.

And http://msdn2.microsoft.com/en-us/library/ms177191.aspx unambiguously
states that you should use % to get a tracking handle, not &.
{
...
}
}
};

The compile generates the error message "error C2446: '!=' : no conversion
from 'const CManaged' to 'CManaged ^const '" when the line "if( this !=
&a )" is uncommented. While this is to be expected, what is the proper
way to check if the source and destination objects are the same?

Ian

Oct 24 '06 #3

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

Similar topics

2
by: Dave | last post by:
Hi, I'm writing a research simulation program and would like to write it in c++. It should be as fast as possible and am not sure if it makes a difference to use managed or unmanaged code. I will...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
0
by: Johannes Unfried | last post by:
Problem Best practice needed to marshal STL data from managed code to unmanaged code & vice vers Details managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a...
2
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 afterwards with ILDASM at what is visible in those assemblies from a...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
1
by: Sparhawk | last post by:
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...
3
by: JoeProgrammer | last post by:
A couple of questions re. managed vs. unmanaged code. 1. I know this depends on the app, but how much faster is unmanaged code vs. managed code? Is there an average figure for this? 2. Is it as...
6
by: nicolas.hilaire | last post by:
Hi all, i'm not totally clear with some concepts about managed and unmanaged code. I'm asking myself some questions : - i've a MFC app, i want to use the framework dotnet by switching to...
20
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Sorry to bring up a topic that is just flogging a dead horse.... but... On the topic of memory management.... I am doing some file parcing that has to be done as quick as posible, but what I...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
0
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...
0
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,...
0
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...
0
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...

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.