【问题标题】:Parameter count mismatch with Windows Form ShowDialog delegate参数计数与 Windows 窗体 ShowDialog 委托不匹配
【发布时间】: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


    【解决方案1】:

    原来我传入了三个参数,昨晚我太累了,没注意到。

    我已将代码压缩为:

    delegate void ShowErrorWindow(ErrorThrowClass ^ form, System::String^ strErrorMessage, int iNumberOfSegments );
    
    void ThrowErrorWindow(System::String^ strErrorMessage, int iNumberOfSegments, System::Windows::Forms::Form ^ parentForm)
    {
    //Only throw if we need too.
    if(!bErrorPause)
    {
        ShowErrorWindow ^ disp = gcnew ShowErrorWindow(&ErrorThrowClass::LaunchErrorWindow);
        MthrControl(DataProtect,M_UNLOCK,M_DEFAULT);
        try
        {
            array<Object^> ^ Args = {parentForm, strErrorMessage, iNumberOfSegments};
            parentForm->Invoke(disp, Args);
        }
        catch(Exception ^e)
        {
            e->Message;
        }
        MthrControl(DataProtect,M_LOCK,M_DEFAULT);
    }
    } //end Throw ErrorWindow
    

    启动另一个错误窗口的代码现在是父 GUI 对象中的静态函数。这允许在一个线程中启动所有内容。

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 2015-12-17
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      相关资源
      最近更新 更多