VC.Net 中 Remoting 技术中,delegate event 客户端定义委托事件的问题
我使用C# Remoting技术实现一个传输信息的DLL,里面定义了一个委托事件,主要实现服务器向客户端发送一些信息public class Remoting_Object : MarshalByRefObject
{
public delegate void ChatRoomEventHandler(string s);
//定义了 1个 "ChatRoomEventHandler 委托类型" 的事件及远程回调函数
public event ChatRoomEventHandler MessageReceive; //消息接收事件
.........
在客户端使用MFC+CLR方式建立的程序,在一个按钮下进行委托事件的注册,不知道要怎样进行注册,如下:
ref class Receiver {
public:
void Handler(String^ s)
{
//Parent->SetWindowText(IDC_BUTTON1,s)
//System::Diagnostics::Debug::WriteLine(s);
//::SendMessage(theApp.GetMainWnd()->GetSafeHwnd(),WM_CLOSE,0,0);
//Console::WriteLine(s);
}
};
void CAdvertise_BroadCastServerDlg::OnBnClickedButton3()
{
// TODO: Add your control notification handler code here
RemotingConfiguration::RegisterWellKnownServiceType(Type::GetType("Advertise_Remote.Remoting_Object,Advertise_Remote"), "RemoteOp", WellKnownObjectMode::SingleCall);
Remoting_Object^ obj = safe_cast<Remoting_Object ^>(Activator::GetObject(Advertise_Remote::Remoting_Object::typeid, "tcp://localhost:8085/RemoteOp"));
if (obj)
{
try
{
Receiver^ rc1 = gcnew Receiver;
obj->MessageReceive += gcnew Advertise_Remote::ChatRoomEventHandler(rc1,&Receiver::Handler);
}
catch ( Exception^ e )
{
TRACE("kkkkkk3");
//Console::WriteLine( "Generic Exception Handler: {0}", e );
//System::Diagnostics::Debug::WriteLine("Generic Exception Handler: {0}", e);
}
......
}
上面是按照MSDN相关帮助自己整的,编译能通过,但运行即出现异常,请高手帮帮忙看看,客户端要使用MFC+CLR方式 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 怎么回复的我看不见啊 --------------------编程问答--------------------
补充:.NET技术 , VC.NET