可视C++窗体应用程序无法在其他计算机上运行
Visual C++ Forms Application won't run on other computers
我是C++的新手,我正在尝试使用Visual C++Express 2010创建一个简单的Forms应用程序。当它只是一个头文件和.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;
}
再次感谢您的帮助。很抱歉,如果这是一个太长和愚蠢的问题
Forms应用程序必须在发布模式下编译,因为VC++Redistributable Package只包括发布dll("应用程序的调试版本不可重新分发,Visual C++库DLL的调试版本也不可重新发布"重新分发Visual C++文件)。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 在其他文件中创建类时在 c++ 项目中不起作用
- 类与私有变量的其他类之间的线程安全性
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- GlobalAlloc而不是其他分配方法
- QT.如何使用QTNetwork在网络上查看其他计算机
- Visual C 程序不在其他计算机中运行
- 在其他计算机 MVCP100d 中打开 EXE 需要什么文件
- 将 c++ 游戏部署到其他窗口计算机
- ShellExecute 不适用于其他计算机
- C++-发送的请求未到达其他计算机
- struct-statc++未在其他计算机中编译
- 将我的DirectX应用程序移植到其他计算机
- Visual C++2010-将项目复制到其他计算机后出现多个未解决的外部错误