473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managed and Unmanaged Compilation

108 New Member
Hi guys,
I created a simple program which combines a managed and unmanaged c++ syntax. I have encountered a problem in compiling this program. The compiler told me to add /clr:oldSyntax but when I added it, the compiler cannot interpret the managed syntax. Hope you can help me.

#include "stdafx.h"

using namespace System;

__nogc class Container
{
int m_value;

public:
Container() : m_value(0) {}
void setValue(int* a_value) { m_value = *a_value; }
const int& getValue() { return m_value; }

};

int main(array<Syst em::String ^> ^args)
{
Console::WriteL ine(L"Hello World");
return 0;
}
Feb 20 '08 #1
2 1455
Banfa
9,065 Recognized Expert Moderator Expert
I created a simple program which combines a managed and unmanaged c++ syntax. I have encountered a problem in compiling this program. The compiler told me to add /clr:oldSyntax but when I added it, the compiler cannot interpret the managed syntax.
Hi, I suspect the compiler was guess at your mistake and got it wrong (no surprise there), /clr:oldSyntax is only for use with legacy projects built with Managed C++ syntax before the newer C++/CLR syntax came in.

I suggest your remove /clr:oldSyntax compile and post the errors you get from that compilation.
Feb 20 '08 #2
romcab
108 New Member
Hi, I suspect the compiler was guess at your mistake and got it wrong (no surprise there), /clr:oldSyntax is only for use with legacy projects built with Managed C++ syntax before the newer C++/CLR syntax came in.

I suggest your remove /clr:oldSyntax compile and post the errors you get from that compilation.

Hi,

Thanks. I post here my solution. Kindly comment if this correct.

// Managed.cpp : main project file.

#include "stdafx.h"

using namespace System;


class MyBase
{
private:
int m_value;

public:
MyBase() : m_value(0) { Console::WriteL ine(L"MyBase constructed is called"); }
void setValue(int a_value) { m_value = a_value; }
const int getValue() { return m_value; }

};


public ref class MyClass
{
public:
MyBase *mb;

public:
MyClass()
{
this->mb = new MyBase();
Console::WriteL ine(L"MyClass constructed is called");
}
};

int main(array<Syst em::String ^> ^args)
{
MyClass ^my = gcnew MyClass();
my->mb->setValue(5);
Console::WriteL ine(my->mb->getValue());
Console::ReadLi ne();
return 0;
}
Feb 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
523
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the managed one is in a namespace MyNameSpace. If want to use my managed DLL in a C# project,so I added : #using
5
2944
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++ libraries. We are using managed C++ as a bridge between managed .NET code and unmanaged C++ code, which I'm sure is a fairly common practice. The managed C++ library is compiled with /CLR whereas all other libraries are compiled without /CLR because...
3
234
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the managed one is in a namespace MyNameSpace. If want to use my managed DLL in a C# project,so I added : #using
3
3495
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the managed one is in a namespace MyNameSpace. If want to use my managed DLL in a C# project,so I added : #using
6
1456
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 /clr compilation mode. Is my app in CLR, or only the call to the
0
8312
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
8827
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...
1
8504
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,...
0
7337
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...
1
6169
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
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
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
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.