Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.5 KiB

  1. #include "CommonUtils.h"
  2. #include <winsock2.h>
  3. _bstr_t
  4. CommonUtils::getCIPAddressCtrlString( CIPAddressCtrl& ip )
  5. {
  6. unsigned long addr;
  7. ip.GetAddress( addr );
  8. PUCHAR bp = (PUCHAR) &addr;
  9. wchar_t buf[BUF_SIZE];
  10. swprintf(buf, L"%d.%d.%d.%d", bp[3], bp[2], bp[1], bp[0] );
  11. return _bstr_t( buf );
  12. }
  13. void
  14. CommonUtils::fillCIPAddressCtrlString( CIPAddressCtrl& ip,
  15. const _bstr_t& ipAddress )
  16. {
  17. // set the IPAddress control to blank if ipAddress is zero.
  18. unsigned long addr = inet_addr( ipAddress );
  19. if( addr != 0 )
  20. {
  21. PUCHAR bp = (PUCHAR) &addr;
  22. ip.SetAddress( bp[0], bp[1], bp[2], bp[3] );
  23. }
  24. else
  25. {
  26. ip.ClearAddress();
  27. }
  28. }
  29. void
  30. CommonUtils::getVectorFromSafeArray( SAFEARRAY*& stringArray,
  31. vector<_bstr_t>& strings )
  32. {
  33. LONG count = stringArray->rgsabound[0].cElements;
  34. BSTR* pbstr;
  35. HRESULT hr;
  36. if( SUCCEEDED( SafeArrayAccessData( stringArray, ( void **) &pbstr)))
  37. {
  38. for( LONG x = 0; x < count; x++ )
  39. {
  40. strings.push_back( pbstr[x] );
  41. }
  42. hr = SafeArrayUnaccessData( stringArray );
  43. }
  44. }
  45. void
  46. CommonUtils::getSafeArrayFromVector(
  47. const vector<_bstr_t>& strings,
  48. SAFEARRAY*& stringArray
  49. )
  50. {
  51. LONG scount = 0;
  52. for( int i = 0; i < strings.size(); ++i )
  53. {
  54. scount = i;
  55. SafeArrayPutElement( stringArray, &scount, (BSTR ) strings[i] );
  56. }
  57. }