[英]Visual C++ Forms Application won't run on other computers
我是C ++的新手,我試圖用Visual C ++ Express 2010創建一個簡單的Forms Application。當它只是一個頭文件和.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
}
};
該文件毫無意義,因為它所做的所有工作都可以在main函數中完成,甚至該類甚至可以在main項目文件中。 我只是試了一下,看它是否可行,但無濟於事。
// 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;
}
再次,任何幫助將不勝感激。 抱歉,如果這個問題太長太愚蠢
由於VC ++可再發行程序包僅包含發行版dll,因此必須在發布模式下編譯Forms應用程序(“不能再發行應用程序的調試版本,而不能再發行Visual C ++庫DLL的調試版本”,即發行Visual C ++文件 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.