Alpaca Tech Blog

ゲーム作る系 草食動物の備忘録

【C++/CLI】OpenFileDialog::ShowDialogでフリーズする

発生

openFileDialog1->ShowDialog();

を実施すると、ダイアログが開かずアプリケーションがフリーズしました。

 

 

原因

エントリーポイントの関数に

[STAThreadAttribute]

指定が無いと、フリーズするみたいでした。

 

using namespace System;
using namespace System::Windows::Forms;

 

[STAThreadAttribute]
int main(array<System::String ^> ^args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    Application::Run(gcnew MyApplication::MainForm());

    return 0;

 

 

 

参考

STAThreadAttribute クラス (System) | Microsoft Docs

STAThreadの意味は? - .NET Tips (VB.NET,C#...)

 

開発環境