Form designer won’t allow you to add new classes before the main form class. In fact you can place a class before the forms main class no problem for the compiler – its just the form editor that won’t have it (you can’t view the form in design view)

To solve this you need to move the class to a seperate header file and include it with all the other includes. This solves the problem. Spent ages trying to define the class, functions etc before the form to get round the problem but whatever you do it causes an error. Get over it and just create a small header file. Whatever your doing would probably be well suited to turning it into a class anyway!!

In the seperate file

namespace {
	public ref class InstallerUpdaterClass
	{
		void InstallerUpdaterClass::UpdaterStartSilent(void)
		{
			try
			{
				//Pause before starting
				Thread::Sleep(10000);		//mS

				String ^UpdaterFilename;
				UpdaterFilename = Path::GetDirectoryName(Application::ExecutablePath);
				UpdaterFilename += "\\" + INSTALLER_UPDATER_FILENAME;

				Process ^UpdaterProcess = Process::Start(UpdaterFilename, "/silent");
				UpdaterProcess->Close();
			}
			catch (Exception ^)
			{
			}
		}
	};
}
In the form you can now use this no problem

	MyNamespace::InstallerUpdaterClass::UpdaterStartSilent()
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.