Has anyone tried to write this tutorial using VC++ 2008 Express? The article claims to be written with VC++ 2005. But I thought 2005 and 2008 used compatible versions of CLR language. I'm getting all kinds of compiler errors -- for example String* str; instead of using String^ str; and creating objects with new instead of gcnew. The last straw for me was while attempting to implement the section concerning FileInfo class. None of the FileInfo methods Microsoft has in that article work.

Recommended Answers

All 4 Replies

The tutorial tells you what to do to compile as Managed C++ instead of C++/CLI:

Note In Visual C++ 2005, you must add the common language runtime support compiler option (/clr:oldSyntax) to successfully compile the previous code sample as Managed C++. To add the common language runtime support compiler option, follow these steps:

  1. Click Project, and then click ProjectName Properties.
    Note ProjectName is a placeholder for the name of the project.
  2. Expand Configuration Properties, and then click General.
  3. In the right pane, click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project settings.
  4. Click Apply, and then click OK.

For more information about common language runtime support compiler options, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx (http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx)

When I change that I get this warning

1>cl : Command line warning D9035 : option 'clr:oldsyntax' has been deprecated and will be removed in a future release

Then get other errors, such as this one (line 19 in the code shown below).
Form1.h(22) : error C2059: syntax error : 'public'

namespace test5 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
    using namespace System::IO;
	/// <summary>
	/// Summary for Form1
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form

That looks like generated C++/CLI code. None of that fancy stuff will work under the oldSyntax setting. You have to start with an empty project and build it manually, I think. Or find a tutorial that covers the new syntax. The MSDN library has example code in multiple langauges for all of the classes in System::IO and they are up to date for the framework version. C++/CLI is always included from what I've seen. For example.

I was finally able to get that FileInfo stuff figures out, not by MSCN or google but by IntellSense. So now I can continue on with that tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.