473,395 Members | 1,680 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,395 software developers and data experts.

VC++ VS2005 Object instance pointer

2
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 to illustrate the problem:

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" <------------- added (or not)
#pragma once
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {

<---------- various vain attempts -------------------->

// 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
3 1616
weaknessforcats
9,208 Expert Mod 8TB
This looks like C#.

I am moving this to the .NET forum.
Aug 14 '07 #2
pOwner
2
Forget it.

This is VISUAL STUDIO 2005 VC++
auto-generated forms.
w'da mean looks like C# ?

Get a clue. I figured it out anyway. :^|
Aug 14 '07 #3
Forget it.

This is VISUAL STUDIO 2005 VC++
auto-generated forms.
w'da mean looks like C# ?

Get a clue. I figured it out anyway. :^|
Actually, this is C++/CLI so it rightfully belongs in the .NET section.
Aug 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and...
7
by: ultranet | last post by:
I have cruised around http://msdn.microsoft.com/visualc/ and the rest of the site, and i am not able to find a single C++ or VC++ certification exam that will be available after June 30, 2004. I...
37
by: Greg | last post by:
Except for legacy or non-.NET applications, is there any reason to use VC++ anymore? It seems that for .NET applications, there would be no reason to choose C++ over C# since C# is faster to...
0
by: tccode97 | last post by:
To whom it may concern, I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
2
by: Mayur | last post by:
Hello all, Can any one have the source of How to add event handler in unmanaged MFC application for event source which is in Managed(c# class library). Here is the Event Source code :...
17
by: Fabry | last post by:
Hi All, I'm new of this group and I do not know if this is the correct group for my question. I have a DLL with its export library (.lib) wrote in Borland C++ 6. In borland everything is OK and...
4
by: nmrcarl | last post by:
I'm trying to upgrade a large project from VS 6.0 to VS 2005. After fixing a lot of things that changed (mostly sloppy coding in the original project that VS2005 didn't allow), I got the release...
15
by: Michael Tissington | last post by:
I have a Visual Basic 6.0 ActiveX Control. It seems there is no way with VS 2005 to create a similar control for containers that host ActiverX controls, is this correct ? I'm thinking of...
3
by: =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?= | last post by:
Hi all, I am porting my code in VC++ to VC.net i.e managed. I have seen somewhere that i need to convert my char* to String*, but String * doesnt perform pointer arithmetic like String* p; *p++='...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.