snmp_pp.cpp
上传用户:czjinwang
上传日期:2007-01-12
资源大小:2484k
文件大小:2k
源码类别:

SNMP编程

开发平台:

Visual C++

  1. // snmp_pp.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include <afxdllx.h>
  5. #include "winsock.h"
  6. #include "winsnmp.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern CRITICAL_SECTION my_critical_section; 
  13. static AFX_EXTENSION_MODULE Snmp_ppDLL = { NULL, NULL };
  14. extern "C" int APIENTRY
  15. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  16. {
  17. WORD wVersionReq;
  18. WSADATA wsaData;
  19. int err;
  20. #ifdef _DLL_ATTACH_OPTION
  21. smiUINT32 nMajVer, nMinVer, nLevel, nTrans, nReTrans;
  22. SNMPAPI_STATUS status;
  23. #endif
  24. wVersionReq = MAKEWORD(1,1);
  25. if (dwReason == DLL_PROCESS_ATTACH)
  26. {
  27. TRACE0("SNMP_PP.DLL Initializing!n");
  28. // set up snmp critical section object
  29. InitializeCriticalSection( &my_critical_section);
  30. // fire up WinSock
  31. err = WSAStartup( wVersionReq, &wsaData);
  32. if (err!=0)
  33. TRACE0("Failed to Startup WinSock!n");
  34. else
  35. TRACE0("Startup WinSock OK");
  36. #ifdef _DLL_ATTACH_OPTION
  37. // start up WinSNMP
  38. status = SnmpStartup(&nMajVer,
  39.                              &nMinVer,
  40.                              &nLevel,
  41.                              &nTrans,
  42.                              &nReTrans);
  43.         if ( status !=  SNMPAPI_SUCCESS ) {
  44. TRACE0("Unable to Startup WinSNMP!n");
  45. return 0;
  46. }
  47. TRACE0("Startup WinSNMP OKn");
  48. #endif
  49. // Extension DLL one-time initialization
  50. AfxInitExtensionModule(Snmp_ppDLL, hInstance);
  51. // Insert this DLL into the resource chain
  52. new CDynLinkLibrary(Snmp_ppDLL);
  53. }
  54. else if (dwReason == DLL_PROCESS_DETACH)
  55. {
  56. // free up critical section object
  57. DeleteCriticalSection( &my_critical_section);
  58. TRACE0("SNMP_PP.DLL Terminating!n");
  59. #ifdef _DLL_ATTACH_OPTION
  60. if ( SnmpCleanup() != SNMPAPI_SUCCESS) TRACE0("-- SNMP++, SnmpCleanup Failuren");
  61. #endif
  62. // shut down WinSock
  63. WSACleanup();
  64. }
  65. return 1;   // ok
  66. }