#ifdef UNICODE

#include <windows.h>

HANDLE WINAPI FindFirstFileA( LPCSTR path, LPWIN32_FIND_DATAA data ) {
	WCHAR wbuffer[MAX_PATH];
	HANDLE ret;
	WIN32_FIND_DATAW wdata;

	if( !MultiByteToWideChar( CP_ACP, 0, path, -1, wbuffer, MAX_PATH ) ) {
		return INVALID_HANDLE_VALUE;
	}

	ret = FindFirstFileW( wbuffer, &wdata );
	if( ret != INVALID_HANDLE_VALUE ) {
		memcpy( data, &wdata, FIELD_OFFSET( WIN32_FIND_DATAA, cFileName ) );
		WideCharToMultiByte( CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL );
	}

	return ret;
}

BOOL WINAPI FindNextFileA( HANDLE handle, LPWIN32_FIND_DATAA data ) {
	BOOL ret;
	WIN32_FIND_DATAW wdata;

	ret = FindNextFileW( handle, &wdata );
	if( ret != FALSE ) {
		memcpy( data, &wdata, FIELD_OFFSET( WIN32_FIND_DATAA, cFileName ) );
		WideCharToMultiByte( CP_ACP, 0, wdata.cFileName, -1, data->cFileName, MAX_PATH, NULL, NULL );
	}

	return ret;
}

BOOL WINAPI MoveFileA( LPCSTR from, LPCSTR to ) {
	WCHAR wfrom[MAX_PATH];
	WCHAR wto[MAX_PATH];
	BOOL ret;

	if( !MultiByteToWideChar( CP_ACP, 0, from, -1, wfrom, MAX_PATH ) ) {
		return FALSE;
	}
	if( !MultiByteToWideChar( CP_ACP, 0, to, -1, wto, MAX_PATH ) ) {
		return FALSE;
	}

	ret = MoveFileW( wfrom, wto );
	return ret;
}

BOOL WINAPI DeleteFileA( LPCSTR path ) {
	WCHAR wbuffer[MAX_PATH];
	BOOL ret;

	if( !MultiByteToWideChar( CP_ACP, 0, path, -1, wbuffer, MAX_PATH ) ) {
		return FALSE;
	}

	ret = DeleteFileW( wbuffer );
	return ret;
}

HINSTANCE WINAPI LoadLibraryA( LPCSTR path ) {
	WCHAR wbuffer[MAX_PATH];
	HINSTANCE ret;

	if( !MultiByteToWideChar( CP_ACP, 0, path, -1, wbuffer, MAX_PATH ) ) {
		return NULL;
	}

	ret = LoadLibraryW( wbuffer );
	return ret;
}

DWORD WINAPI GetCurrentDirectoryA( DWORD nBufferLength, LPSTR lpBuffer ) {
#ifdef _WIN32_WCE
	WCHAR wbuffer[MAX_PATH];
	char *s;
	int len;

	if( !GetModuleFileName( GetModuleHandle( NULL ), wbuffer, MAX_PATH ) ) {
		return 0;
	}
	if( !( len = WideCharToMultiByte( CP_ACP, 0, wbuffer, -1, lpBuffer, nBufferLength, NULL, NULL ) ) ) {
		return 0;
	}

	s = strrchr( lpBuffer, '\\' );
	if( s ) {
		*s = 0;
	}

	return ( DWORD )( s - lpBuffer );
#else
	WCHAR wbuffer[MAX_PATH];
	int len;

	if( !GetCurrentDirectoryW( MAX_PATH, wbuffer ) ) {
		return 0;
	}

	len = WideCharToMultiByte( CP_ACP, 0, wbuffer, -1, lpBuffer, nBufferLength, NULL, NULL );
	return len;
#endif
}

int WINAPI MessageBoxA( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType ) {
	WCHAR wText[4096];
	WCHAR wCaption[64];
	int ret;

	if( !MultiByteToWideChar( CP_ACP, 0, lpText, -1, wText, 4096 ) ) {
		return 0;
	}
	if( !MultiByteToWideChar( CP_ACP, 0, lpCaption, -1, wCaption, 64 ) ) {
		return 0;
	}

	ret = MessageBoxW( hWnd, wText, wCaption, uType );
	return ret;
}

BOOL WINAPI CreateDirectoryA( LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ) {
	WCHAR wbuffer[MAX_PATH];
	BOOL ret;

	if( !MultiByteToWideChar( CP_ACP, 0, lpPathName, -1, wbuffer, MAX_PATH ) ) {
		return FALSE;
	}

	ret = CreateDirectoryW( wbuffer, lpSecurityAttributes );
	return ret;
}

BOOL WINAPI GetFileAttributesExA( LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation ) {
	WCHAR wbuffer[MAX_PATH];
	BOOL ret;

	if( !MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, wbuffer, MAX_PATH ) ) {
		return FALSE;
	}

	ret = GetFileAttributesExW( wbuffer, fInfoLevelId, lpFileInformation );
	return ret;
}

#endif /* UNICODE */

