Multithreading 从类.NET外部调用
我使用VisualStudioC++ 2010。< /P> 我想在GUI中从主线程以外的其他线程、从主窗体类之外声明的函数进行线程安全更改。以下是我的一些代码: 在主类之外: 146行是:Multithreading 从类.NET外部调用,multithreading,c++-cli,invoke,Multithreading,C++ Cli,Invoke,我使用VisualStudioC++ 2010。< /P> 我想在GUI中从主线程以外的其他线程、从主窗体类之外声明的函数进行线程安全更改。以下是我的一些代码: 在主类之外: 146行是: DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate(Global->FORM, &Form1::DEBUGDelegateMethod); =================================================== @编
DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate(Global->FORM, &Form1::DEBUGDelegateMethod);
===================================================
@编辑
在Form1声明后移动lua_debug后,我得到以下错误:
d:\prog\c++\x\x\Form1.h(1829): error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'X::Form1 ^'
1> No user-defined-conversion operator available, or
1> Cast from base to derived requires safe_cast or static_cast
1>d:\prog\c++\x\x\Form1.h(1829): error C3754: delegate constructor: member function 'X::Form1::DEBUGDelegateMethod' cannot be called on an instance of type 'System::Windows::Forms::Form ^'
一致:
DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate(Global->FORM, &Form1::DEBUGDelegateMethod);
全局->表单声明为:
static Form^ FORM;
在Globals类中。尝试将lua_debug的定义移动到Form1的下面,或者像对DEBUGDelegateMethod所做的那样向前声明Form1。我假设它们都在同一个名称空间lua_debug和Form1中。如果没有,则在第146行中,必须预处理名称空间,即:&YourNamespace::Form1::DEBUGDelegateMethod
编辑:根据OP的编辑
只是沮丧:
DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate( dynamic_cast<X::Form1^>(Global->FORM ), &Form1::DEBUGDelegateMethod);
看起来lua_调试函数看不到Form1类型。第一个错误表明了这一点,其他两个是第一个错误的结果。我想有些信息不见了。Form1是在命名空间中定义的吗?lua_debug和Form1是否在同一个文件中?哪一个先去?包括?pragmas?Form1在名称空间内定义,lua_debug和Form1都在Form1.h文件中,首先声明lua_debug,然后是Form1-lua_debug在buttonclick在Form1上创建的新线程中调用。出现新错误:错误C2440:“初始化”:无法从“System::Windows::Forms::Form^”转换为“X::Form1^”
d:\prog\c++\x\x\Form1.h(1829): error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'X::Form1 ^'
1> No user-defined-conversion operator available, or
1> Cast from base to derived requires safe_cast or static_cast
1>d:\prog\c++\x\x\Form1.h(1829): error C3754: delegate constructor: member function 'X::Form1::DEBUGDelegateMethod' cannot be called on an instance of type 'System::Windows::Forms::Form ^'
DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate(Global->FORM, &Form1::DEBUGDelegateMethod);
static Form^ FORM;
DEBUGDelegate^ myDelegate = gcnew DEBUGDelegate( dynamic_cast<X::Form1^>(Global->FORM ), &Form1::DEBUGDelegateMethod);