I have recently started programming in C++/CLI. I have done a lot of research on the net trying to locate an answer to this problem, but there seems to be a lack of Tutorials and books on C++/CLI.
I have read 4 of the published books as best I could. The one book that has a great deal of info for my interest was Pro Visual C++/CLI and the .NET 2.0 platform by Fraser.
Problem:
Using VS2005 C++ and writing C++/CLI code, and using the "Designer", I created a basic Windows form, populated it with a menustrip, and an Open File menu (short snippet of C++/CLI from "Form1.h":
Expand|Select|Wrap|Line Numbers
- public: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
- {
- // System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
- static int ii=1;
- openFileDialog1->ShowDialog(); // *** has memory leak must be disposed.
- String^ filePath = openFileDialog1->FileName;
- label1->Text = filePath;
- label2->Text = "Counting";
- Dyn_XML_Obj.File_List->Add(filePath); // put path into File_List (keeps track of all open XML docs.)
However, inorder to get these working, I had to place the class definitions at the top of the Form like this:
Expand|Select|Wrap|Line Numbers
- #pragma once
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h> // allows use of abort()
- #include <vector> // include the STL vector (Standard Template Library for vector which is a type of list.
- #include <iostream> // To use iostream commands such as cout, cin
- #include <process.h> // so I can clear the screen.
- #using <System.xml.dll> // so we can access XmlDocument
- using namespace System::Xml;
- using namespace std; // so we can shorten from std::vector to vector
- using namespace System::IO; // se we can use Directory methods
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- namespace WFC_3a {
- int ii; // Put your variables here
- public ref class Dyn_XML_Class
- {
- public:
- ArrayList^ File_List; // Will hold the filenames of XML files.
- ArrayList^ XML_List; // Will hold the XmlDocument objects for each VALID item in File_List.
- Dyn_XML_Class() // CONSTRUCTOR
- {
- File_List = gcnew ArrayList(16); // Initialize File_List with 16 empty items.
- XML_List = gcnew ArrayList(16); // Initialize XML_List with 16 empty items.
- Console::WriteLine("File_List Constructor Completed.");
- }
- void ADD()
- {Console::WriteLine("You have called ADD.");}
- };
- public ref class XML_Class
- {
- public:
- XmlDocument^ XML_Doc;
- static int Doc_Total;
- int My_Num;
- XML_Class()
- {
- XML_Doc = gcnew XmlDocument();
- My_Num=Doc_Total;
- Doc_Total++;
- }
- void show()
- {
- // Console::WriteLine("hello, My_Num={0},{1}",My_Num,Doc_Total);
- }
- };
1. Once I placed the classes there I "Broke" the designer... and it would no longer work to let me see the visual layout of my form.
2. Attempting to Move the class definitions to WFC_3a.cpp resulted in 82 errors that everything in those classes was missing and syntax errors.
3. Attempting to move the classes to the same file Form1.h, but at the bottom also creates 82 errors:
Form1.h(185) : error C2227: left of '->Add' must point to class/struct/union/generic type
Form1.h(192) : error C2059: syntax error : '>'
and many more "Missing ;" and Syntax errors.
So, questions are:
1. Where should I move these classes and what code should I use so that Form1 will recognize the classes... without damaging the "designer" functions of VS2005.
Thank you.