简体   繁体   English

Visual C ++窗体应用程序将无法在其他计算机上运行

[英]Visual C++ Forms Application won't run on other computers

I'm very new to C++ and I am trying to create a simple Forms Application with Visual C++ Express 2010. I got it to compile with no errors when it was just a header file and a .cpp file and it ran on my computer perfectly fine. 我是C ++的新手,我试图用Visual C ++ Express 2010创建一个简单的Forms Application。当它只是一个头文件和.cpp文件并且可以在我的计算机上完美运行时,我可以将其编译为没有错误。精细。 When I tried to give my friend the compiled .exe to run, it didn't run. 当我尝试让我的朋友运行已编译的.exe时,它没有运行。 He had the .NET framework 4.5 and the Visual C++ 2010 redistributable package and it still refused to work. 他拥有.NET Framework 4.5和Visual C ++ 2010可再发行组件包,但仍然无法正常工作。 He says it just won't start up at all(I don't know if it gives him an error message). 他说根本就不会启动(我不知道这是否会给他一个错误信息)。 All the program had was a button that changed a label. 程序中只有一个按钮可以更改标签。 I'm tearing my hair out here because I can't seem to get this to work on any other computer but my own. 我在这里扯头发是因为我似乎无法让它在我自己的计算机上工作。 Please help me understand why this will not run on another computer. 请帮助我理解为什么它不能在另一台计算机上运行。 It could be an error I made, so the code is down below. 这可能是我犯的错误,因此代码如下。 As you can see, I've turned it into 3 .cpp files to see if that would work. 如您所见,我将其转换为3个.cpp文件,以查看是否可行。 There's alot of pointless code here, but it still compiles fine. 这里有很多毫无意义的代码,但是仍然可以编译。

//Source2.cpp
#pragma once



    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
    /// </summary>
    public ref class Header1 : public System::Windows::Forms::Form
    {
    public:
        Header1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Header1()
        {
            if (components)
            {
                delete components;
            }
        }
    public: System::Windows::Forms::Button^  button1;
            System::Windows::Forms::Label^  label1;

    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->label1 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(13, 13);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Header1::button1_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(13, 43);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(46, 17);
            this->label1->TabIndex = 1;
            this->label1->Text = L"label1";
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(282, 253);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 this->label1->Text = "works";
             }
    };

^^Note that this was originally a header file called Header1.h ^^请注意,这最初是一个名为Header1.h的头文件。

//Source1.cpp
#include "stdafx.h"
#include "Source2.cpp"//used to include Header1.h


public class runpr
{
public:
    runpr()
    {
        create();
    }

    ~runpr();

private:
    void create()
    {
    // 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 Header1());
//^^all of this was originally in the main function
    }
};

This file is pretty pointless because all of what it does could just be done in the main function or the class could even be in the main project file. 该文件毫无意义,因为它所做的所有工作都可以在main函数中完成,甚至该类甚至可以在main项目文件中。 I just tried it to see if it would work, but to no avail. 我只是试了一下,看它是否可行,但无济于事。

// Testing123.cpp : main project file.

#include "stdafx.h"
#include "Source1.cpp"



[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    runpr* start = new runpr;
//creates an instance of runpr class
    return 0;
}

Again, any help would be appreciated. 再次,任何帮助将不胜感激。 Sorry if this was too long and stupid of a question 抱歉,如果这个问题太长太愚蠢

由于VC ++可再发行程序包仅包含发行版dll,因此必须在发布模式下编译Forms应用程序(“不能再发行应用程序的调试版本,而不能再发行Visual C ++库DLL的调试版本”,即发行Visual C ++文件 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM