Windows10,VS2017Community,C++/CLI 開発者用コマンドプロンプト 使用
f1.cpp ひとつに全プログラムを書いています。
これでグローバルにアクセス出来ると思います。
コード:
rem コンパイル後リンク
cl /clr f1.cpp
rem 実行結果
f1.exe
f1.cpp
コード:
///参照設定
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.Data.dll>
///ヘッダーファイル
#include<stdio.h>
///使用名前空間
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Diagnostics;//←ここを追加
ref class MyForm : public Form
{
public:
Stopwatch^ sw;
private:
Button^ button1;
TextBox^ txtBox;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
MyForm::sw->Start();
this->txtBox->Text = L"Stopwatch Started!";
}
public : MyForm() //コンストラクタ
{
this->button1 = gcnew Button();
this->txtBox = gcnew TextBox();
this->Text = L"MyForm";
//MyForm->Size = System::Drawing::Size(300,300);//デフォルト
this->Location = System::Drawing::Point(100,100);
this->button1->Location = System::Drawing::Point(30,60);
this->txtBox ->Location = System::Drawing::Point(30,20);
this->button1->Text = L"Btn";
this->txtBox->Text = L"txtBox";
this->Controls->Add(button1);
this->Controls->Add(txtBox );
this->button1->Click += gcnew System::EventHandler(this,&MyForm::button1_Click);
this->sw = gcnew Stopwatch();
}
};//end class
//エントリー・ポイント
int main()
{
// メイン ウィンドウを作成して、実行します
Application::Run(gcnew MyForm());
return 0;
}
実行
コード:
D:\z17c\clr\f02>f
D:\z17c\clr\f02>rem コンパイル後リンク
D:\z17c\clr\f02>cl /clr f1.cpp
Microsoft(R) C/C++ Optimizing Compiler Version 19.10.25019
for Microsoft(R) .NET Framework Version 4.07.2101.1
Copyright (C) Microsoft Corporation. All rights reserved.
f1.cpp
Microsoft (R) Incremental Linker Version 14.10.25019.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:f1.exe
f1.obj
D:\z17c\clr\f02>rem 実行結果
D:\z17c\clr\f02>f1.exe
D:\z17c\clr\f02>f
D:\z17c\clr\f02>rem コンパイル後リンク
D:\z17c\clr\f02>cl /clr f1.cpp
Microsoft(R) C/C++ Optimizing Compiler Version 19.10.25019
for Microsoft(R) .NET Framework Version 4.07.2101.1
Copyright (C) Microsoft Corporation. All rights reserved.
f1.cpp
Microsoft (R) Incremental Linker Version 14.10.25019.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:f1.exe
f1.obj
D:\z17c\clr\f02>rem 実行結果
D:\z17c\clr\f02>f1.exe
D:\z17c\clr\f02>