0

私は C++ に非常に慣れていないので、Visual C++ Express 2010 を使用して単純なフォーム アプリケーションを作成しようとしています。ヘッダー ファイルと .cpp ファイルだけで、コンピューター上で完全に実行されたときに、エラーなしでコンパイルできました。大丈夫。コンパイル済みの .exe を友人に渡して実行させようとしたところ、実行されませんでした。彼は .NET Framework 4.5 と Visual C++ 2010 再頒布可能パッケージを持っていましたが、それでも動作しませんでした。彼は、まったく起動しないと言います(エラーメッセージが表示されるかどうかはわかりません)。プログラムにあったのは、ラベルを変更するボタンだけでした。私は自分のコンピューター以外ではこれを動作させることができないように見えるので、ここで髪を引き裂いています。これが別のコンピューターで実行されない理由を理解してください。これは私が作ったエラーかもしれないので、コードは下にあります。ご覧のとおり、 3 に変更しました。cpp ファイルを調べて、それが機能するかどうかを確認します。ここには無意味なコードがたくさんありますが、それでも問題なくコンパイルされます。

//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";
             }
    };

^^これはもともと 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
    }
};

このファイルはほとんど意味がありません。なぜなら、それが行うことはすべてメイン関数で実行できるか、クラスがメイン プロジェクト ファイルにある可能性さえあるからです。動作するかどうか試してみましたが、役に立ちませんでした。

// 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;
}

繰り返しますが、助けていただければ幸いです。これが長すぎてばかげた質問だったらごめんなさい

4

1 に答える 1

0

VC++ 再頒布可能パッケージにはリリース DLL しか含まれていないため、フォーム アプリケーションはリリース モードでコンパイルする必要があります (「アプリケーションのデバッグ バージョンは再頒布可能ではなく、Visual C++ ライブラリ DLL のデバッグ バージョンは再頒布可能ではありません」Visual C++ ファイルの再配布)。

于 2013-08-29T08:39:35.473 に答える