/*	XGPostWinOSError.cpp
 *
 *		This knows how to deal with the MacOS Errors
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#include <XConfig.h>			// must be first to optimize compile on MSVC++

#if OPT_WINOS == 1

#include <string.h>
#include <XError.h>
#include <XDataUtil.h>

/************************************************************************/
/*																		*/
/*	Construction														*/
/*																		*/
/************************************************************************/

/*$	XGPostWinOSError::XGPostWinOSError
 *
 *		Create this error, appending the OS Error string to the message
 *	passed to me
 */

XGPostWinOSError::XGPostWinOSError(DWORD err, unsigned long msg, ...)
{
	va_list vlist;
	
	va_start(vlist,msg);
	SetMessage(msg,vlist);
	va_end(vlist);
	
	fErrorID = err;
}

/************************************************************************/
/*																		*/
/*	Error Messages														*/
/*																		*/
/************************************************************************/

/*$	XGPostWinOSError::GetLongError
 *
 *		Get the message string. This actually looks up the error message
 *	that was passed in the constructor and appends it to the error
 *	description.
 */

void XGPostWinOSError::GetLongError(char *dest)
{
	char buffer[80];
	char buf2[256];
	
	XGPostError::GetLongError(buffer);
	GetErrorString(fErrorID,buf2);
	yformat(dest,"#S: #S",buf2,buffer);
}	

/************************************************************************/
/*																		*/
/*	Error Formatting													*/
/*																		*/
/************************************************************************/

/*$	XGPostWinOSError::GetErrorString
 *
 *		Get the error string. Looks up the error message associated with
 *	this Microsoft Windows specific OS error.
 */

void XGPostWinOSError::GetErrorString(DWORD err, char *str)
{
	::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
					FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL,
					err,
					MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
					str,
					128,
					(char **)NULL);
}

#endif
