forked from weimingtom/onscripter_jh_sdl2_fork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.h
92 lines (87 loc) · 2.32 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* -*- C++ -*-
*
* Utils.h
*
* Copyright (C) 2014 jh10001 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __UTILS_H__
#define __UTILS_H__
#ifdef ANDROID
#include <android/log.h>
#elif defined(WINRT)
#include "debugapi.h"
#include "windows.h"
static BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
{
DWORD dwMinSize;
dwMinSize = MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, NULL, 0);
if (dwSize < dwMinSize)
{
return FALSE;
}
MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdarg.h>
#if defined(_MSC_VER)
#include <windows.h>
#endif
namespace utils{
inline void printInfo(const char *format, ...){
va_list ap;
va_start(ap, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_VERBOSE, "Info", format, ap);
#elif defined(WINRT)
char *buf = new char[256];
vsprintf(buf, format, ap);
LPWSTR wstr = new WCHAR[128];
MByteToWChar(buf, wstr, 256);
OutputDebugString(wstr);
#elif defined(_MSC_VER)
char *buf = new char[256];
vsprintf(buf, format, ap);
OutputDebugString(buf);
#else
vprintf(format, ap);
#endif
va_end(ap);
}
inline void printError(const char *format, ...){
va_list ap;
va_start(ap, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_ERROR, "ERR", format, ap);
#elif defined(WINRT)
char *buf = new char[256];
vsprintf(buf,format,ap);
LPWSTR wstr = new WCHAR[128];
MByteToWChar(buf, wstr, 256);
OutputDebugString(wstr);
#elif defined(_MSC_VER)
char *buf = new char[256];
vsprintf(buf, format, ap);
OutputDebugString(buf);
#else
vfprintf(stderr, format, ap);
#endif
va_end(ap);
}
}
#endif