snmp_pp.cpp
资源名称:hp_snmp3.zip [点击查看]
上传用户:czjinwang
上传日期:2007-01-12
资源大小:2484k
文件大小:2k
源码类别:
SNMP编程
开发平台:
Visual C++
- // snmp_pp.cpp : Defines the initialization routines for the DLL.
- //
- #include "stdafx.h"
- #include <afxdllx.h>
- #include "winsock.h"
- #include "winsnmp.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CRITICAL_SECTION my_critical_section;
- static AFX_EXTENSION_MODULE Snmp_ppDLL = { NULL, NULL };
- extern "C" int APIENTRY
- DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
- {
- WORD wVersionReq;
- WSADATA wsaData;
- int err;
- #ifdef _DLL_ATTACH_OPTION
- smiUINT32 nMajVer, nMinVer, nLevel, nTrans, nReTrans;
- SNMPAPI_STATUS status;
- #endif
- wVersionReq = MAKEWORD(1,1);
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- TRACE0("SNMP_PP.DLL Initializing!n");
- // set up snmp critical section object
- InitializeCriticalSection( &my_critical_section);
- // fire up WinSock
- err = WSAStartup( wVersionReq, &wsaData);
- if (err!=0)
- TRACE0("Failed to Startup WinSock!n");
- else
- TRACE0("Startup WinSock OK");
- #ifdef _DLL_ATTACH_OPTION
- // start up WinSNMP
- status = SnmpStartup(&nMajVer,
- &nMinVer,
- &nLevel,
- &nTrans,
- &nReTrans);
- if ( status != SNMPAPI_SUCCESS ) {
- TRACE0("Unable to Startup WinSNMP!n");
- return 0;
- }
- TRACE0("Startup WinSNMP OKn");
- #endif
- // Extension DLL one-time initialization
- AfxInitExtensionModule(Snmp_ppDLL, hInstance);
- // Insert this DLL into the resource chain
- new CDynLinkLibrary(Snmp_ppDLL);
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- // free up critical section object
- DeleteCriticalSection( &my_critical_section);
- TRACE0("SNMP_PP.DLL Terminating!n");
- #ifdef _DLL_ATTACH_OPTION
- if ( SnmpCleanup() != SNMPAPI_SUCCESS) TRACE0("-- SNMP++, SnmpCleanup Failuren");
- #endif
- // shut down WinSock
- WSACleanup();
- }
- return 1; // ok
- }