我使用snmp_pp.doc中的trap receiver 的例子,但是编译之后报以下的错误。清高手指教。error C2664:
'int __thiscall Snmp::notify_register(const class SnmpCollection<class Oid> &,const class SnmpCollection<class CTarget> &,void (__cdecl *const )(int,class Snmp *,cl
ass Pdu &,class SnmpTarget &,void *),const void *)' : cannot convert parameter 3 from 'void (__cdecl *)(int,class Snmp *,class Pdu &,class TimeTicks &,class SnmpTarget &,void *)' to 'void (__cdecl *const )(int,class Snmp *,class Pdu &,class SnmpTarg
et &,void *)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
'int __thiscall Snmp::notify_register(const class SnmpCollection<class Oid> &,const class SnmpCollection<class CTarget> &,void (__cdecl *const )(int,class Snmp *,cl
ass Pdu &,class SnmpTarget &,void *),const void *)' : cannot convert parameter 3 from 'void (__cdecl *)(int,class Snmp *,class Pdu &,class TimeTicks &,class SnmpTarget &,void *)' to 'void (__cdecl *const )(int,class Snmp *,class Pdu &,class SnmpTarg
et &,void *)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
解决方案 »
- 如何设置一个文件的属性为不可读写
- 关于Ribbon:VC怎么设置RibbonCheckBox状态?
- 父窗口发送WM_PAINT消息,子窗口或控件会跟着响应吗?
- 哪里有WINDOWS常见任务那样的控件源码?
- 长期挂贴!!关于QQ农场的山寨版MFC制作!!求啊
- 预编译头文件问题
- 一个菜鸟问题 about listcontrl
- 如何在一个对话框中实现对另一个对话框中ComboBox的字符串的添加?
- 请教一个问题:怎么样把程序所需要的声音,图片等资源 与 运行程序 编译成一个可执行程序???谢谢!!
- 一个CString s="0101",怎么把它转换成16进制的0x05
- 请教:网络接收与网络发送不能同时用?
- 如何释放加载到宿主程序中的dll
ass Pdu &,class SnmpTarget &,void *)
Snmp* session, // session handle
Pdu & pdu, // trap pdu
TimeTicks ×tamp, // timestamp
SnmpTarget &target, // source of the trap
void * cbd) // optional callback data
{
GenAddress address;
unsigned char get_cummunity[80], set_community[80];
unsigned long timeout;
int retry;
unsigned char v=2;
if(reason == SNMP_CLASS_NOTIFICATION) target.resolve_to_C( OctetStr(get_cummunity,80), // get community
OctetStr(set_community,80), // set community
address, // address object
timeout, // timeout
retry, // retry
v); //v1 or v2 // cout << "Trap Received from:"
// << address->get_printable()
// << "Trap Id = "
// << trapid.get_printable();
}
Snmp *snmp;//---------------[ trap receive register ]---------------------------------------------------------------------
// dynamic Snmp object
void trap_register()
{
int status;
snmp = new Snmp( status);
if (( snmp == NULL) || ( status != SNMP_CLASS_SUCCESS))
cout <<"Error constructing Snmp Object\n";
else
{
//-------[ set up two empty collections, empty denotes receive all ]-------------------------------
TargetCollection targets;
OidCollection trapids;
//------[ invoke the regsiter ]---------------------------------------------------------------------------- // snmp->notify_set_listen_port (162) ; if(status = snmp->notify_register(trapids, targets, &my_trap_callback) != SNMP_CLASS_SUCCESS)
cout <<"Snmp Trap Register Error " << snmp->error_msg(status);
} }
我终于自己找到问题了。
在这里说明一下。是基本的回调函数应用的错误。我在trap_register() 中加了 snmp_callback p; //snmp_callback 是snmp_pp.h中定义的函数指针
p = my_trap_callback; //把我定义的函数my_trap_callback的地址付给p把notify_register(trapids, targets, &my_trap_callback)中最后一个参数改为p.