/*
 * MEM : メモリ表示アプリケーション：メインルーチン
 * Copyright(C) 1997-1999 Eiichiro Ito
 *
 * 1998/05/17:Eiichiro Ito
 *  (1) 作成開始
 * 修正履歴
 *
 */
#include	"conslib.h"
#include	<tchar.h>

TCHAR	AppName[] = TEXT("MEM") ;	/* 必須項目 */

TCHAR	MessageBuf[ 256 ] ;

HINSTANCE	hLib = 0 ;
BOOL		(*MyGetDiskFreeSpaceExW)( LPCWSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailableToCaller, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes ) = 0 ;

int
Main( DWORD argc, LPTSTR argv[] )
{
	int					ret = 0 ;
#ifdef	_WIN32_WCE
	STORE_INFORMATION	si ;
	MEMORYSTATUS		ms ;
	ULARGE_INTEGER		dummy, total, free ;
	LPCTSTR				pccard = TEXT("/Storage Card") ;

	memset( &ms, 0, sizeof ms ) ;
	ms.dwLength = sizeof ms ;
	GlobalMemoryStatus( &ms ) ;
	wsprintf( MessageBuf, TEXT("%10d %s\n"),
			  ms.dwTotalPhys,
			  TEXT("bytes total conventional memory") ) ;
	Cputs( MessageBuf ) ;
	wsprintf( MessageBuf, TEXT("%10d %s\n"),
			  ms.dwAvailPhys,
			  TEXT("bytes available conventional memory") ) ;
	Cputs( MessageBuf ) ;
	Cputs( TEXT("\n") ) ;
	if ( GetStoreInformation( &si ) ) {
		wsprintf( MessageBuf, TEXT("%10d %s\n"),
				  si.dwStoreSize,
				  TEXT("bytes total object store memory") ) ;
		Cputs( MessageBuf ) ;
		wsprintf( MessageBuf, TEXT("%10d %s\n"),
				  si.dwFreeSize,
				  TEXT("bytes available object store memory") ) ;
		Cputs( MessageBuf ) ;
		Cputs( TEXT("\n") ) ;
	}
	hLib = LoadLibrary( TEXT("COREDLL.DLL") ) ;
	if ( hLib != NULL ) {
		MyGetDiskFreeSpaceExW = (BOOL(*)(LPCWSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER)) GetProcAddress( hLib, TEXT("GetDiskFreeSpaceExW") ) ;
		FreeLibrary( hLib ) ;
	}
	if ( MyGetDiskFreeSpaceExW ) {
		if ( (*MyGetDiskFreeSpaceExW)( pccard, &dummy, &total, &free ) ) {
			wsprintf( MessageBuf, TEXT("%10d %s\n"),
					  total.LowPart,
					  TEXT("bytes total PC-Card memory") ) ;
			Cputs( MessageBuf ) ;
			wsprintf( MessageBuf, TEXT("%10d %s\n"),
					  free.LowPart,
					  TEXT("bytes available PC-Card memory") ) ;
			Cputs( MessageBuf ) ;
			ret = 1 ;
		}
	}
#endif	/* _WIN32_WCE */
	return ret ;
}
