2
我正在嘗試使用指向託管對象的非託管函數觸發事件。我得到以下錯誤:從非託管函數中觸發事件
error C3767:
'ShashiTest::test::OnShowResult::raise'
: candidate function(s) not accessible
我怎麼能沒有任何問題調用常規函數ShowMessage?
#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);
}
}
這不是一個c + +的問題 –
可能重複[C++/cli傳遞(託管)委託給非託管代碼](http://stackoverflow.com/questions/2972452/c-cli-pass-managed-delegate-to -unmanaged代碼) –