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.

41 lines
940 B

  1. #ifndef __NmStd_h__
  2. #define __NmStd_h__
  3. // Useful macros
  4. inline LONG RectWidth(const RECT* pr) { return pr->right - pr->left; }
  5. inline LONG RectHeight(const RECT* pr) { return pr->bottom - pr->top; }
  6. inline LONG RectWidth(const RECT& rpr) { return rpr.right - rpr.left; }
  7. inline LONG RectHeight(const RECT& rpr) { return rpr.bottom - rpr.top; }
  8. inline HRESULT GetLocalIPAddress( DWORD *pdwIPAddress )
  9. {
  10. HRESULT hr = S_OK;
  11. if( pdwIPAddress )
  12. {
  13. // get local host name
  14. CHAR szLocalHostName[MAX_PATH];
  15. szLocalHostName[0] = '\0';
  16. gethostname(&szLocalHostName[0], MAX_PATH);
  17. // get the host entry by name
  18. PHOSTENT phe = gethostbyname(&szLocalHostName[0]);
  19. if (phe != NULL)
  20. {
  21. // get info from the host entry
  22. *pdwIPAddress = *(DWORD *) phe->h_addr;
  23. }
  24. else
  25. {
  26. hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_INTERNET,WSAGetLastError());
  27. }
  28. }
  29. else
  30. {
  31. hr = E_INVALIDARG;
  32. }
  33. return hr;
  34. }
  35. #endif // ! _NMUTIL_H_