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

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#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														*/
/*																		*/
/************************************************************************/

//	@G"Constructor/Destructor"

/*	@F"XGPostWinOSError::XGPostWinOSError" @I
 *
 *		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														*/
/*																		*/
/************************************************************************/

// @G"Public Methods"

/*	@F"XGPostWinOSError::GetLongError" @I
 *
 *		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													*/
/*																		*/
/************************************************************************/

/*	@F"XGPostWinOSError::GetErrorString" @I
 *
 *		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
