473,382 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Microsoft make brain bleed

I'm trying to create a pointer to a class in form1.h button1 event
handler. It should be simple... but no. This example is as simple as I
can make:

Form1.h (produced with the designer containing a single button)
************************************************** *********************************
#pragma once
namespace MyProject {

using namespace System;
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
{
public:
Form1(void)
{
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::Button^ button1;
// private: MyClass^ MyPtr;
protected:

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->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(91, 65);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(104, 32);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
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(292, 256);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);

}
#pragma endregion
#include "MyClass.h"
#pragma once
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
// MyClass^ MyPtr = gcnew MyClass();
// MyPtr->MyMethod();
MyClass instance;
instance.MyMethod();
}
};
}

************************
At the end here, I want to have the event handler for button 1 execute
MyMethod();

MyClass.h Produced by adding a C++ class
*****************************
#pragma once

ref class MyClass
{
public:
MyClass(void);
static void MyMethod(void);
};
***********************************************
MyClass.cpp

#include "StdAfx.h"
#include "MyClass.h"
#include "Form1.h"

using namespace MyProject;

MyClass::MyClass(void)
{
}
void MyClass::MyMethod()
{
}
************************************************** *
MyProject.cpp

// MyProject.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace MyProject;

[STAThreadAttribute]
int main(array<System::String ^^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(fal se);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
************************************************** **********

I don't want to have to put all my executable code in Form1.h
I want to have separate files for unrelated classes and call them from
various event handlers.
The way the files are as shown I get LNK2020 unresolved token.
If I pull the #include "MyClass.h" from Form1.h I get error C2065
undeclared identifier.

I'm fit to be tied. I've spent hours searching for an answer and it
seems to be a common problem world-wide with no resolution. I've tried
all the old fashioned ways too. MyClass* pMyClass = new MyClass();
etc.

Anybody able to help?
TIA

Aug 14 '07 #1
0 930

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jaz | last post by:
Hello all, I'd like to have a background image bleed of the right side of my page, but I don't want the page to stretch out with a scroll bar. How might I go about this? I can't make it a...
2
by: Jon | last post by:
Hi all, I am trying to create a page that contains a number of div elements, with links on the left side of the page allowing the user to select which div to display. Some of the pages contain...
476
by: Xah Lee | last post by:
Microsoft Hatred, FAQ Xah Lee, 20020518 Question: U.S. Judges are not morons, and quite a few others are not morons. They find MS guilty, so it must be true. Answer: so did the German...
2
by: Skipper_23 | last post by:
can anyone help me out, how to use multiple tables in one form using microsoft access?
7
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.