积极答复者
如何迁移SnmpMgrTrapListen

问题
-
我是个新手,我想将winsnmpapi中的函数SnmpMgrTrapListen迁移到.net平台,我使用vc++/cli迁移这个函数,迁移后我使用C#测试,我无法接收到来自SnmpMgrTrapListen的事件句柄,请问大家我应该怎么样做才能收到时间句柄,代码如下
// The function registers the ability of an SNMP manager application to receive SNMP traps from the SNMP Trap Service
bool SnmpApiNetClass::CWinSnmpApi::SnmpMgrTrapListenFotDotNet(IntPtr% phTrapAvailable)
{
HANDLE* asnphTrapAvailable;
if(SnmpMgrTrapListen(asnphTrapAvailable))
{
phTrapAvailable = (IntPtr)*asnphTrapAvailable;
return true;
}
return false;
}- 已移动 周雪峰MVP, Moderator 2009年4月27日 2:01 Visual C++问题 ([Loc]From:一般性问题讨论区)
答案
-
WaitForSingleObject是Windows API。你需要在你的代码内声明这个API。AutoResetEvent只能等待类自己创建的事件。
MSMVP VC++- 已标记为答案 KeFang Chen 2009年4月30日 3:50
全部回复
-
谢谢Sheng Jiang,也许我的问题没提清楚。我以前用vc6编写snmp的Trap时,使用WinSnmpAPIi的SnmpMgrTrapListen函数建立event,再使用WaitForSingleObject等待着Event事件。
我使用C++/CLI封装了SnmpMgrTrapListen函数,将Event句柄返回,但是我在C#下使用时找不到WaitForSingleObject函数,无法实现线程间同步。在C#有AutoResetEvent类,但是它无法接受上述的Event句柄,我想知道如何让AutoResetEvent响应SnmpMgrTrapListen建立的Event事件,谢谢
-
WaitForSingleObject是Windows API。你需要在你的代码内声明这个API。AutoResetEvent只能等待类自己创建的事件。
MSMVP VC++- 已标记为答案 KeFang Chen 2009年4月30日 3:50