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::Compone ntModel;
using namespace System::Collect ions;
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)
{
InitializeCompo nent();
//
//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::Compone ntModel::Contai ner ^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 InitializeCompo nent(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->UseVisualStyle BackColor = true;
this->button1->Click += gcnew System::EventHa ndler(this,
&Form1::button1 _Click);
//
// Form1
//
this->AutoScaleDimen sions = System::Drawing ::SizeF(6, 13);
this->AutoScaleMod e = System::Windows ::Forms::AutoSc aleMode::Font;
this->ClientSize = System::Drawing ::Size(292, 256);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(f alse);
}
#pragma endregion
#include "MyClass.h"
#pragma once
private: System::Void button1_Click(S ystem::Object^ sender,
System::EventAr gs^ e) {
// MyClass^ MyPtr = gcnew MyClass();
// MyPtr->MyMethod();
MyClass instance;
instance.MyMeth od();
}
};
}
*************** *********
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::MyClas s(void)
{
}
void MyClass::MyMeth od()
{
}
*************** *************** *************** ******
MyProject.cpp
// MyProject.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace MyProject;
[STAThreadAttrib ute]
int main(array<Syst em::String ^^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::En ableVisualStyle s();
Application::Se tCompatibleText RenderingDefaul t(false);
// Create the main window and run it
Application::Ru n(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 0 948 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 body background since I'm using Mambo as a CMS.
Instead, this image is going to go into a content object which will be
displayed on my front page. There will be a small flash object on top
of the left side of the image, and the image will be wide...
|
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 tables with border
styles used to block off the columns and the headers, but not the
individual rows. The pages will be displayed using IE 5.5 and later
in the finished app. Now to the problem, which is a little awkward to
describe:
|
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 population thought Jews are morons by
heritage, to the point that Jews should be exterminated from earth.
Apparently, the entire German population cannot be morons, they must be
|
by: Skipper_23 |
last post by:
can anyone help me out, how to use multiple tables in one form using
microsoft access?
|
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 Server 01 is brought back up? It still thinks it is
the primary because that was its role when it crashed and it does not know
about the takeover by force command that was issued. Does the 01 server
check the 02 server to see what role they are in...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |