0
- showmessage 메서드가 호출 될 때마다 이벤트를 발생시키고 싶습니다. C# 코드에서 catch하고 싶습니다.이벤트 처리 C++/cli를 사용하여 C#
- 이벤트를 작성했습니다.
가 결정됨을 내가 함수 showmessage에게 와 대리자를 연결 초기화 기능에서 수행 한 내용을 수정
C++/CLI
delegate void progressmsgdisplay(System::String^message);
progressmsgdisplay^progressMsgNotify;
void Mclass::ShowMessage(System::String^message)
{
MessageBox(NULL, m_msg, m_box, NULL);
notify(message);
}
event progressmsgdisplay^notify
{
void add(progressmsgdisplay^d)
{
progressMsgNotify += d;
}
void remove(progressmsgdisplay^d)
{
progressMsgNotify -= d;
}
void raise(System::String^msg)
{
progressmsgdisplay^tmp = progressMsgNotify;
if (tmp)
{
tmp->Invoke(msg);
}
}
}
//void Mclass::Initialize(System::String^strProgressMsg)
//{
// progressMsgNotify=gcnew progressmsgdisplay(this,&Mclass::ShowMessage);
//}
-Mclass이의 이름입니다 C#에서이 이벤트를 사용하는 - 어떻게
클래스는있는 위의 모든 선언이이 속임수를 썼는지C#
void display(string progressnotification)
{
Console.Out.WriteLine(progressnotification);
}
void initialize()
{
first = new Mclass();
first.notify()+=display;
}
정의
오류 C2664 : 'managed :: Mclass :: someEvent :: raise': 'System :: String ^'에서 'System :: EventArgs ^'로 매개 변수 2를 변환 할 수 없습니다. \t 이 오류는 기본 raise 메서드는 두 번째 매개 변수로 System :: EventArgs^args가 필요하고 System :: string을 전달해야합니다. –
EventHandler 대리인이 문제를 해결할 것으로 추측합니다. 이것을 읽으십시오 : http://msdn.microsoft.com/en-us/library/db0etb8x.aspx. 주어진 예를 확인하십시오. –
http://stackoverflow.com/questions/9699740/using-eventhandler-in-c-cli –