Using DotNET API in MFC application
-
Hi All, I wanted to use NET API in my MFC application, since this was new to me I started out with a simple application listed below #include "stdafx.h" #include "myapp.h" #using #using using namespace System; // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { // TODO: code your application's behavior here. Console::WriteLine("This is a MFC app using NET API"); } return nRetCode; } Till few days back I was able to successfully compile and run this simple application using VC++ 2005 with SP1, however now when I am trying to compile the application I am getting the following error 1>.\myapp.cpp(45) : error C3666: 'System::Security::IEvidenceFactory::IEvidenceFactory' : override specifier 'new' not allowed on a constructor 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : error C3611: 'System::Security::IEvidenceFactory::GetLifetimeService': a sealed function cannot have a pure-specifier 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : error C4687: 'System::Console': a sealed abstract class cannot implement an interface 'System::Security::IEvidenceFactory' 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1> This diagnostic occurred while impor
-
Hi All, I wanted to use NET API in my MFC application, since this was new to me I started out with a simple application listed below #include "stdafx.h" #include "myapp.h" #using #using using namespace System; // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { // TODO: code your application's behavior here. Console::WriteLine("This is a MFC app using NET API"); } return nRetCode; } Till few days back I was able to successfully compile and run this simple application using VC++ 2005 with SP1, however now when I am trying to compile the application I am getting the following error 1>.\myapp.cpp(45) : error C3666: 'System::Security::IEvidenceFactory::IEvidenceFactory' : override specifier 'new' not allowed on a constructor 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : error C3611: 'System::Security::IEvidenceFactory::GetLifetimeService': a sealed function cannot have a pure-specifier 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : error C4687: 'System::Console': a sealed abstract class cannot implement an interface 'System::Security::IEvidenceFactory' 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1> This diagnostic occurred while impor
You cannot use the .NET framework from a native application (MFC, C, C++, whatever). If you want to use applications that exploit the features of .NET framework, then you will need to write code in one of those managed languages (C#, VB.NET, CLI/C++)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]
-
Hi All, I wanted to use NET API in my MFC application, since this was new to me I started out with a simple application listed below #include "stdafx.h" #include "myapp.h" #using #using using namespace System; // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { // TODO: code your application's behavior here. Console::WriteLine("This is a MFC app using NET API"); } return nRetCode; } Till few days back I was able to successfully compile and run this simple application using VC++ 2005 with SP1, however now when I am trying to compile the application I am getting the following error 1>.\myapp.cpp(45) : error C3666: 'System::Security::IEvidenceFactory::IEvidenceFactory' : override specifier 'new' not allowed on a constructor 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : error C3611: 'System::Security::IEvidenceFactory::GetLifetimeService': a sealed function cannot have a pure-specifier 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : error C4687: 'System::Console': a sealed abstract class cannot implement an interface 'System::Security::IEvidenceFactory' 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1> This diagnostic occurred while impor
You can make a dll and use of it on the c++ or vice versa.