本文介绍了从非托管函数触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用指向托管对象的指针从非托管函数中触发事件
我收到以下错误.
错误C3767:``ShashiTest :: test :: OnShowResult :: raise'':候选函数无法访问
我怎么能正常调用ShowMessage函数.
I am trying to fire an event from a unmanaged function using a pointer to managed object
I get the following error.
error C3767: ''ShashiTest::test::OnShowResult::raise'': candidate function(s) not accessible
How ever I can call regular function ShowMessage without any issue.
#pragma once
#using<mscorlib.dll>
#using<system.windows.forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Diagnostics;
using namespace System::Windows::Forms;
namespace ShashiTest {
public delegate void ShowResult(System::String^);
public ref class test
{
public:
event ShowResult^ OnShowResult;
test(void)
{
};
void ShowMessage()
{
MessageBox::Show("Hello World");
}
};
class ManagedInterface
{
public:
gcroot<test^> m_test;
ManagedInterface(){};
~ManagedInterface(){};
void ResultWindowUpdate(std::string ResultString);
};
}
void ShashiTest::ManagedInterface::ResultWindowUpdate(std::string ResultString)
{
if(m_test)
{
System::String ^result = gcnew system::String(ResultString.c_str());
m_test->OnShowResult(result);
}
}</system.windows.forms.dll></mscorlib.dll>
推荐答案
这篇关于从非托管函数触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!