【发布时间】:2011-12-13 02:36:00
【问题描述】:
所以我只是想从与 GUI 线程不同的线程中显示一个表单。对于我的一生,我看不到为调用正确设置我的参数,这给了我来自 catch 的错误消息:
“参数计数不匹配”
任何想法我应该如何正确设置要传入的参数?
#pragma once
#include "ErrorSystemStop.h"
using namespace System;
using namespace System::Windows::Forms;
delegate DialogResult ShowErrorWindow(System::Windows::Forms::IWin32Window ^ parentForm );
void ThrowErrorWindow(System::String^ strErrorMessage, int iNumberOfSegments, System::Windows::Forms::IWin32Window ^ parentForm)
{
//Only throw if we need too.
if(!bErrorPause)
{
MainDisplay::ErrorSystemStop ^ stopMe = gcnew MainDisplay::ErrorSystemStop(strErrorMessage, iNumberOfSegments);
ShowErrorWindow ^ disp = gcnew ShowErrorWindow(( System::Windows::Forms::Form ^)stopMe, &MainDisplay::ErrorSystemStop::ShowDialog);
stopMe->TopMost = true;
try
{
cli::array<System::Windows::Forms::IWin32Window ^> ^ Args = gcnew cli::array<System::Windows::Forms::IWin32Window ^>(1);
Args[0] = parentForm;
stopMe->Invoke(disp,( System::Windows::Forms::Form ^)stopMe, gcnew array<System::Object ^>{Args});
}
catch(Exception ^e)
{
e->Message;
}
}
} //end ThrowErrorWindow
我也试过了:
array<Object^> ^ Args = {parentForm};
stopMe->Invoke(disp,(System::Windows::Forms::Form ^)stopMe, Args);
谢谢,
阿利卡
【问题讨论】:
标签: .net delegates c++-cli invoke