473,809 Members | 2,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about the dreaded MC++

Can managed C++ be trusted to handle the garbage collector correctly in the
right bit if I have a project with unmanaged and managed parts in it?
Nov 17 '05 #1
24 2817
Yes.

Is there something more specific you are after?

Ronald Laeremans
Visual C++ team

"songie D" <so****@D.com > wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Can managed C++ be trusted to handle the garbage collector correctly in
the
right bit if I have a project with unmanaged and managed parts in it?

Nov 17 '05 #2
> Yes.

OK, good! I'd heard rumours that you "constantly have to worry about what
the gc's doing", but I've not ran into any problems with that, as yet.

Is there something more specific you are after?
ermm...yes, now you come to mention it.
I'm trying to add
using namespace System::Runtime ::InteropServic es;

to my project, but it gives the error

C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\Platfo rmSDK\Include\W inBase.h(3139) : error C2872: 'FILETIME' :
ambiguous symbol

could be 'C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\Platfo rmSDK\Include\W inDef.h(354) : _FILETIME FILETIME'

or 'stdafx.cpp(0) : System::Runtime ::InteropServic es::FILETIME'

many times. I can get round it by putting the explicit namespace name
preceeding all calls to the namespace, but that's a bit cumbersome. Any idea
how I can resolve it?

Also, for having an unmanaged function in one separate .cpp file, and the
managed code in what the IDE gives you (i.e. Form1.h), how would I link to
the unmanaged function, using extern "C"? or other?
Would I have to put #pragma unmanaged round the declaration?

Ronald Laeremans
Visual C++ team

"songie D" <so****@D.com > wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Can managed C++ be trusted to handle the garbage collector correctly in
the
right bit if I have a project with unmanaged and managed parts in it?


Nov 17 '05 #3
Songie,
ermm...yes, now you come to mention it.
I'm trying to add
using namespace System::Runtime ::InteropServic es;

to my project, but it gives the error

C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\Platfo rmSDK\Include\W inBase.h(3139) : error C2872: 'FILETIME' :
ambiguous symbol

could be 'C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\Platfo rmSDK\Include\W inDef.h(354) : _FILETIME FILETIME'

or 'stdafx.cpp(0) : System::Runtime ::InteropServic es::FILETIME'

many times. I can get round it by putting the explicit namespace name
preceeding all calls to the namespace, but that's a bit cumbersome. Any idea how I can resolve it?
Using a typedef is a simple way around it:

typedef System::Runtime ::InteropServic es::FILETIME NETFT;

NETFT tm....;


Also, for having an unmanaged function in one separate .cpp file, and the
managed code in what the IDE gives you (i.e. Form1.h), how would I link to
the unmanaged function, using extern "C"? or other?
Header files would work just fine.
Would I have to put #pragma unmanaged round the declaration?


nope. You might want to put it on the definition of the function if you
really want to ensure the compiler generates x86 code (instead of CIL) for
it, though (although you could simply compile the containing .cpp file
without /clr, as well).

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #4
Your problem is you are including a header, probally windows.h, after the using namespace statement. Just put all your includes before the using namespace statements to get rid of the errors

There are some other problems with using the windows.h file and .Net in the same file. For example MessageBox is a macro, so if your trying to get System::Windows ::Forms::Messag eBox, you may find the compilier looking for System::Windows ::Forms::Messag eBoxA. To get around this you have to use #undef for the macro after including the header. This one is only a problem if you try to use MessageBox.
Nov 17 '05 #5
There are no files with '#include' statements AND 'using namespace' statements
The 'Form1.h' has 'using namespace' statements, and the stdafx.h has '#include <windows.h>'
There's no file in which there's both.
Nov 17 '05 #6
How would I compile one file without /clr and the rest with /clr, while building the project all at once?
Nov 17 '05 #7
"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote in message news:<#Z******* *******@TK2MSFT NGP09.phx.gbl>. ..
Yes.

Is there something more specific you are after?

Well, I must say I ran into a few problems with mixed MC++ / C++ when
you make heavy use of the RAII idiom : the .NET runtime seems to have
difficulties with tracking lifetime of parameters, which can have some
nasty side effects, even i f they are not related to GC.

See http://groups.google.com/groups?hl=f....vc.language.*
for the last dirty one.

Arnaud
MVP - VC
Nov 17 '05 #8
Songie,
How would I compile one file without /clr and the rest with /clr, while

building the project all at once?

Select the file in question in solution explorer, and use the properties
dialog box to configure compiler arguments.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #9
mmm... ok. You can do this, yes

I've given up on using managed c++ anyway now, it seems that passing arrays is a whole lot more difficul
than it is in c#, even though its in the same assembly. See further up posts.
Nov 17 '05 #10

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

Similar topics

1
1206
by: Jay donnell | last post by:
in the code below 'print locals()' shows mc2. What is the equivalent way to see the namespace that mc resides in? class myClass: --def func1(self): ----self.mc = 1 ----mc2 = 3 ----print 'in myClass.func1' ----print 'printing locals'
28
2460
by: caustik | last post by:
I don't care if its bad C++, I really dont. I need to convert from a member function pointer to a "void*" with zero computational overhead. I have the perfect way to do it right here, but i'm having troubles because if the member function pointer i pass to the function is not void with no params, I get a casting error. Any ideas how to do this?
2
4041
by: Thomas | last post by:
I have a question about how the stl map class works. I have a subscription class that I use to manage client application subscriptions. These are stored in a map. Periodically, I need to update the subscriptions in the map to reflect changes to data. When I iterate over the map, I expect to get a reference to the object stored in the map using myclass mc = *iter->second; What I am finding is that the copy constructor is getting...
6
1457
by: Nurchi BECHED | last post by:
I have a filename and its process id in brackets. The problem is, the filename can contain brackets and numbers in it, but the last number in the brackets is always the process id. Now, assume, the process name (3344 is the id): myfilename.something else ()(321) (3344) (the actual filename is "myfilename.something else ()(321) (3344).exe")
5
1537
by: Ladvánszky Károly | last post by:
I'm trying to use a statically linked C library. I've wrapped a .NET C++ DLL around this lib and trying to drive the wrapper from a .NET VB testbed. The whole build succeeds but I get the following error message at runtime: An unhandled exception of type 'System.TypeLoadException' occurred in TiffLibXTester.exe Additional information: Could not load type tiff from assembly TiffLibX, Version=1.0.1425.19884, Culture=neutral,...
2
2520
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
11
427
by: Key9 | last post by:
Hi all This is an simple app : read cin and print to cout I want it's action like "cat" with out arguement. #include <iostream> #include <string> using namespace std;
20
1925
by: David | last post by:
I feel like an idiot asking this but here goes: I understand the 'concept' of scope and passing data by value and/or by reference but I am confused on some specifics. class example{ int i; //my global var private void method1(int myInt){ int x; //local var etc...
3
2908
by: Peter Proost | last post by:
Hi group first of all I need to say that I almost never use regex hence my question may be stupid. I'm using regex to find all words that start with an @ in a string. But the regex that I figured doesn't work. can anyone help me. Dim myReg As New Regex("\b@\w*\b") Dim mcCol As MatchCollection Dim mc As Match mcCol = myReg.Matches("@param1 @param2 @test +56 -23 *25) 'I would like to get @param1 and @param2 and @test
0
9721
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
10633
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
10376
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...
0
10114
tracyyun
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...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
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
4331
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
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
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...

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.