util.cpp
上传用户:glass0516
上传日期:2010-01-11
资源大小:104k
文件大小:2k
- /*****************************************************************************
- * RelayFax Open Source Project
- * Copyright 1996-2004 Alt-N Technologies, Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted only as authorized by the RelayFax Open
- * Source License. A copy of this license is available in file LICENSE
- * in the top-level directory of the distribution.
- *
- * RelayFax is a registered trademark of Alt-N Technologies, Ltd.
- *
- * Individual files and/or contributed packages may be copyright by
- * other parties and subject to additional restrictions.
- *****************************************************************************/
- #include "stdafx.h"
- #include "util.h"
- extern HINSTANCE g_Instance;
- string LoadString( UINT uID )
- {
- char szBuffer[1024];
- string s;
- int nRet = ::LoadString( g_Instance, uID, szBuffer, sizeof(szBuffer) );
- nRet = GetLastError();
-
- s.assign( szBuffer );
- return s;
- }
- //
- // FUNCTION: GetLastErrorText
- //
- // PURPOSE: copies error message text to string
- //
- // PARAMETERS:
- // lpszBuf - destination buffer
- // dwSize - size of buffer
- //
- // RETURN VALUE:
- // destination buffer
- //
- // COMMENTS:
- //
- LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize )
- {
- DWORD dwRet;
- LPTSTR lpszTemp = NULL;
- dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
- NULL,
- GetLastError(),
- LANG_NEUTRAL,
- (LPTSTR)&lpszTemp,
- 0,
- NULL );
- // supplied buffer is not long enough
- if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) )
- lpszBuf[0] = TEXT(' ');
- else
- {
- lpszTemp[lstrlen(lpszTemp)-2] = TEXT(' '); //remove cr and newline character
- _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() );
- }
- if ( lpszTemp )
- LocalFree((HLOCAL) lpszTemp );
- return lpszBuf;
- }
- void trimws(char *str)
- {
- char *ptr = str + strlen(str) - 1;
- while (ptr >= str && (*ptr == ' ' || *ptr == 't' || *ptr == 'r' || *ptr == 'n'))
- *ptr-- = ' ';
- ptr = str;
- while (*ptr == ' ' || *ptr == 't' || *ptr == 'r' || *ptr == 'n')
- ptr++;
- if (ptr != str)
- strcpy(str, ptr);
- }