Expression must have a class type C++ with Windows Forms in Visual Studio

I’m creating this program that will act a a “toolbox” to help do some work quickly while on sites. It’ll be a GUI with various buttons for actions. On it there is a place to add an IP of the system to perform actions on. I have one button where I am trying to copy a file from another pc to the one I am currently working on. However when I apply my code to the private section I get the error “expression must have a class type.” I’m not sure where I am dropping the ball here.

    `#pragma once
#include <iostream>
#include <time.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <filesystem>
#include <Windows.h>

#define private public
#define class struct

namespace DEMOLICENSESELECTION {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Threading;
    using namespace std;

    /// <summary>
    /// Summary for MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^ label1;
    protected:
    private: System::Windows::Forms::Button^ button1;
    private: System::Windows::Forms::Button^ button2;
    private: System::Windows::Forms::Button^ button3;
    private: System::Windows::Forms::Button^ button4;
    private: System::Windows::Forms::Button^ button5;
    private: System::Windows::Forms::Button^ button6;
    private: System::Windows::Forms::Button^ button7;
    private: System::Windows::Forms::Button^ button8;
    private: System::Windows::Forms::Button^ button9;
    private: System::Windows::Forms::Button^ button10;
    private: System::Windows::Forms::Button^ button11;
    private: System::Windows::Forms::Button^ button12;
    private: System::Windows::Forms::Button^ button13;
    private: System::Windows::Forms::Label^ label2;
    private: System::Windows::Forms::MenuStrip^ menuStrip1;

    private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
    private: System::Windows::Forms::TextBox^ textBox1;

    public:
    private: System::ComponentModel::IContainer^ components;
    private:

    private:





    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>


#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->label1 = (gcnew System::Windows::Forms::Label());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->button4 = (gcnew System::Windows::Forms::Button());
            this->button5 = (gcnew System::Windows::Forms::Button());
            this->button6 = (gcnew System::Windows::Forms::Button());
            this->button7 = (gcnew System::Windows::Forms::Button());
            this->button8 = (gcnew System::Windows::Forms::Button());
            this->button9 = (gcnew System::Windows::Forms::Button());
            this->button10 = (gcnew System::Windows::Forms::Button());
            this->button11 = (gcnew System::Windows::Forms::Button());
            this->button12 = (gcnew System::Windows::Forms::Button());
            this->button13 = (gcnew System::Windows::Forms::Button());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
            this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->menuStrip1->SuspendLayout();
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left)
                | System::Windows::Forms::AnchorStyles::Right));
            this->label1->AutoSize = true;
            this->label1->Font = (gcnew System::Drawing::Font(L"Bell MT", 36, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Underline)),
                System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
            this->label1->ForeColor = System::Drawing::Color::White;
            this->label1->Location = System::Drawing::Point(135, 24);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(858, 56);
            this->label1->TabIndex = 0;
            this->label1->Text = L"Synectics Demo License Selection Tool";
            // 
            // button1
            // 
            this->button1->BackColor = System::Drawing::SystemColors::GrayText;
            this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button1->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button1->Location = System::Drawing::Point(175, 102);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(374, 50);
            this->button1->TabIndex = 1;
            this->button1->Text = L"Base Core";
            this->button1->UseVisualStyleBackColor = false;
            this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
            // 
            // button2
            // 
            this->button2->BackColor = System::Drawing::SystemColors::GrayText;
            this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button2->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button2->Location = System::Drawing::Point(175, 162);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(374, 50);
            this->button2->TabIndex = 2;
            this->button2->Text = L"All Modules";
            this->button2->UseVisualStyleBackColor = false;
            this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
            // 
            // button3
            // 
            this->button3->BackColor = System::Drawing::SystemColors::GrayText;
            this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button3->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button3->Location = System::Drawing::Point(175, 222);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(374, 50);
            this->button3->TabIndex = 3;
            this->button3->Text = L"All Integrations";
            this->button3->UseVisualStyleBackColor = false;
            this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
            // 
            // button4
            // 
            this->button4->BackColor = System::Drawing::SystemColors::GrayText;
            this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button4->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button4->Location = System::Drawing::Point(175, 282);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(374, 50);
            this->button4->TabIndex = 4;
            this->button4->Text = L"Advanced Alarm Management";
            this->button4->UseVisualStyleBackColor = false;
            this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
            // 
            // button5
            // 
            this->button5->BackColor = System::Drawing::SystemColors::GrayText;
            this->button5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button5->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button5->Location = System::Drawing::Point(175, 342);
            this->button5->Name = L"button5";
            this->button5->Size = System::Drawing::Size(374, 50);
            this->button5->TabIndex = 5;
            this->button5->Text = L"Dashboards";
            this->button5->UseVisualStyleBackColor = false;
            this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
            // 
            // button6
            // 
            this->button6->BackColor = System::Drawing::SystemColors::GrayText;
            this->button6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button6->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button6->Location = System::Drawing::Point(175, 402);
            this->button6->Name = L"button6";
            this->button6->Size = System::Drawing::Size(374, 50);
            this->button6->TabIndex = 6;
            this->button6->Text = L"Dataveillance";
            this->button6->UseVisualStyleBackColor = false;
            this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click);
            // 
            // button7
            // 
            this->button7->BackColor = System::Drawing::SystemColors::GrayText;
            this->button7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button7->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button7->Location = System::Drawing::Point(175, 462);
            this->button7->Name = L"button7";
            this->button7->Size = System::Drawing::Size(374, 50);
            this->button7->TabIndex = 7;
            this->button7->Text = L"Custom Forms and Reports";
            this->button7->UseVisualStyleBackColor = false;
            this->button7->Click += gcnew System::EventHandler(this, &MyForm::button7_Click);
            // 
            // button8
            // 
            this->button8->BackColor = System::Drawing::SystemColors::GrayText;
            this->button8->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button8->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button8->Location = System::Drawing::Point(175, 522);
            this->button8->Name = L"button8";
            this->button8->Size = System::Drawing::Size(374, 50);
            this->button8->TabIndex = 8;
            this->button8->Text = L"Advanced Incident Management";
            this->button8->UseVisualStyleBackColor = false;
            this->button8->Click += gcnew System::EventHandler(this, &MyForm::button8_Click);
            // 
            // button9
            // 
            this->button9->BackColor = System::Drawing::SystemColors::GrayText;
            this->button9->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button9->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button9->Location = System::Drawing::Point(175, 582);
            this->button9->Name = L"button9";
            this->button9->Size = System::Drawing::Size(374, 50);
            this->button9->TabIndex = 9;
            this->button9->Text = L"Active Directory";
            this->button9->UseVisualStyleBackColor = false;
            this->button9->Click += gcnew System::EventHandler(this, &MyForm::button9_Click);
            // 
            // button10
            // 
            this->button10->BackColor = System::Drawing::SystemColors::GrayText;
            this->button10->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button10->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button10->Location = System::Drawing::Point(175, 642);
            this->button10->Name = L"button10";
            this->button10->Size = System::Drawing::Size(374, 50);
            this->button10->TabIndex = 10;
            this->button10->Text = L"Advanced Mapping";
            this->button10->UseVisualStyleBackColor = false;
            this->button10->Click += gcnew System::EventHandler(this, &MyForm::button10_Click);
            // 
            // button11
            // 
            this->button11->BackColor = System::Drawing::SystemColors::GrayText;
            this->button11->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button11->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button11->Location = System::Drawing::Point(175, 702);
            this->button11->Name = L"button11";
            this->button11->Size = System::Drawing::Size(374, 50);
            this->button11->TabIndex = 11;
            this->button11->Text = L"Multi-Site Management";
            this->button11->UseVisualStyleBackColor = false;
            this->button11->Click += gcnew System::EventHandler(this, &MyForm::button11_Click);
            // 
            // button12
            // 
            this->button12->BackColor = System::Drawing::SystemColors::GrayText;
            this->button12->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button12->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button12->Location = System::Drawing::Point(175, 762);
            this->button12->Name = L"button12";
            this->button12->Size = System::Drawing::Size(374, 50);
            this->button12->TabIndex = 12;
            this->button12->Text = L"Application Failover and Replication";
            this->button12->UseVisualStyleBackColor = false;
            this->button12->Click += gcnew System::EventHandler(this, &MyForm::button12_Click);
            // 
            // button13
            // 
            this->button13->BackColor = System::Drawing::SystemColors::GrayText;
            this->button13->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button13->ForeColor = System::Drawing::SystemColors::InfoText;
            this->button13->Location = System::Drawing::Point(175, 822);
            this->button13->Name = L"button13";
            this->button13->Size = System::Drawing::Size(374, 50);
            this->button13->TabIndex = 13;
            this->button13->Text = L"Workflows";
            this->button13->UseVisualStyleBackColor = false;
            this->button13->Click += gcnew System::EventHandler(this, &MyForm::button13_Click);
            // 
            // label2
            // 
            this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->label2->Location = System::Drawing::Point(591, 308);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(494, 230);
            this->label2->TabIndex = 14;
            this->label2->Text = L"Please Select A License To Apply";
            this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
            this->label2->Click += gcnew System::EventHandler(this, &MyForm::label2_Click);
            // 
            // menuStrip1
            // 
            this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) { this->exitToolStripMenuItem });
            this->menuStrip1->Location = System::Drawing::Point(0, 0);
            this->menuStrip1->Name = L"menuStrip1";
            this->menuStrip1->Size = System::Drawing::Size(1121, 24);
            this->menuStrip1->TabIndex = 15;
            this->menuStrip1->Text = L"menuStrip1";
            // 
            // exitToolStripMenuItem
            // 
            this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
            this->exitToolStripMenuItem->Size = System::Drawing::Size(38, 20);
            this->exitToolStripMenuItem->Text = L"Exit";
            this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::exitToolStripMenuItem_Click_1);
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(684, 222);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(298, 20);
            this->textBox1->TabIndex = 16;
            // 
            // MyForm
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->BackColor = System::Drawing::SystemColors::MenuHighlight;
            this->ClientSize = System::Drawing::Size(1121, 890);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->button13);
            this->Controls->Add(this->button12);
            this->Controls->Add(this->button11);
            this->Controls->Add(this->button10);
            this->Controls->Add(this->button9);
            this->Controls->Add(this->button8);
            this->Controls->Add(this->button7);
            this->Controls->Add(this->button6);
            this->Controls->Add(this->button5);
            this->Controls->Add(this->button4);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->menuStrip1);
            this->MainMenuStrip = this->menuStrip1;
            this->Name = L"MyForm";
            this->Text = L"Synectics Demo License Selection Tool";
            this->menuStrip1->ResumeLayout(false);
            this->menuStrip1->PerformLayout();
            this->ResumeLayout(false);
            this->PerformLayout();

        }`private: System::Void button12_Click(System::Object^ sender, System::EventArgs^ e) {
    
        String^ IPAdd1 = textBox1->Text;
                system(("xcopy /y \\"+IPAdd1+"\C$\synergyii\config\clientconfig.xml C:\Test\").c_str()); }

Answer

This is because the string type needs to be used in the system, while IPAdd1 is of the String^ type. I suggest you convert IPAdd1 to string type.

#include <msclrmarshal_cppstd.h>
        
String^ IPAdd1 = textBox1->Text;
std::string str = msclr::interop::marshal_as<std::string>(IPAdd1);
system(("xcopy /y \\" + str + "\C$\synergyii\config\clientconfig.xml C:\Test\").c_str());

Leave a Reply

Your email address will not be published. Required fields are marked *