Click to See Complete Forum and Search --> : Guide me to clear these bugs
sudhavelvizhi
March 19th, 2009, 07:48 AM
I am new to VC++. I am working in Vista with VC++ 2008(professional-trial version)
I hav to create a front end for C program using buttons and all. It has to read the contents of text files. I got one example program from the following link,
http://support.microsoft.com/kb/307398
For this program i got the following error,
1>c:\kb307398\kb307398\Form1.h(22) : error C2059: syntax error : 'public'
1>c:\kb307398\kb307398\Form1.h(22) : error C2059: syntax error : 'public'
1>c:\kb307398\kb307398\Form1.h(23) : error C2143: syntax error : missing ';' before '{'
1>c:\kb307398\kb307398\Form1.h(23) : error C2447: '{' : missing function header (old-style formal list?)
1>.\KB307398.cpp(9) : error C2065: 'array' : undeclared identifier
1>.\KB307398.cpp(9) : error C2275: 'System::String' : illegal use of this type as an expression
1>.\KB307398.cpp(9) : error C2059: syntax error : '>'
1>.\KB307398.cpp(10) : error C2143: syntax error : missing ';' before '{'
1>.\KB307398.cpp(10) : error C2447: '{' : missing function header (old-style formal list?)
I hav verified even the braces match in Form1.h.
GCDEF
March 19th, 2009, 08:13 AM
Post the EXACT code you're trying to compile.
cilu
March 19th, 2009, 10:32 AM
[ redirected ]
That is C++/CLI code you are trying to compile, not C++.
sudhavelvizhi
March 19th, 2009, 11:18 PM
"Form1.h"
#pragma once
namespace project {
using namespace System;
using namespace System::IO;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <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
{
private: String ^win;
public:
Form1(void)
{
win = System::Environment::GetEnvironmentVariable("win");
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ListBox^ listBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->listBox1 = (gcnew System::Windows::Forms::ListBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// listBox1
//
this->listBox1->FormattingEnabled = true;
this->listBox1->Location = System::Drawing::Point(12, 56);
this->listBox1->Name = L"listBox1";
this->listBox1->Size = System::Drawing::Size(202, 225);
this->listBox1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(356, 86);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(64, 34);
this->button1->TabIndex = 1;
this->button1->Text = L"Read";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(751, 359);
this->Controls->Add(this->button1);
this->Controls->Add(this->listBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {// How to read a text file:
// Use try...catch to deal with a 0 byte file or a non-existant file.
listBox1->Items->Clear();
try
{
String^ textFile = String::Concat(win, (S"\\dst_in.txt"));
StreamReader ^reader=gcnew StreamReader(textFile);
do
{
listBox1->Items->Add(reader->ReadLine());
}
while(reader->Peek() != -1);
}
catch(FileNotFoundException ^ex)
{
listBox1->Items->Add(ex);
}
catch (System::Exception ^e)
{
listBox1->Items->Add(e);
}
}
};
}
project.cpp
// project.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace project;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
In project->project properties i hav set Common Language Runtime Support, Old Syntax
sudhavelvizhi
March 20th, 2009, 02:54 AM
I cleared those bugs...
Thank u for ur help.
I hav one more doubt.
Is it possible to call an .exe file from a button click.
cilu
March 20th, 2009, 03:18 AM
Yes. Use CreateProcess() to create a new process.
And next time, please use CODE tags.
sudhavelvizhi
March 21st, 2009, 01:21 AM
I tried some codes using createprocess().
But i'm getting lot of errors.
Can u giv me still some indepth idea abt this.
What is code tag? Where to use it?I dont know abt it.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.