Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / System / WinRT / NptWinRtUtils.cpp
blob714e7fc606f5d8185e8649d68309f51877cd3e55
1 /*****************************************************************
3 | Neptune - WinRT Utilities
5 | (c) 2001-2012 Gilles Boccon-Gibod
6 | Author: Gilles Boccon-Gibod (bok@bok.net)
8 ****************************************************************/
10 /*----------------------------------------------------------------------
11 | includes
12 +---------------------------------------------------------------------*/
13 #include "NptWinRtPch.h"
14 #include "NptWinRtUtils.h"
16 /*----------------------------------------------------------------------
17 | NPT_WinRtUtils::A2WHelper
18 +---------------------------------------------------------------------*/
19 LPWSTR
20 NPT_WinRtUtils::A2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars, UINT acp)
22 int ret;
24 assert(lpa != NULL);
25 assert(lpw != NULL);
26 if (lpw == NULL || lpa == NULL) return NULL;
28 lpw[0] = '\0';
29 ret = MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars);
30 if (ret == 0) {
31 assert(0);
32 return NULL;
34 return lpw;
37 /*----------------------------------------------------------------------
38 | NPT_WinRtUtils::W2AHelper
39 +---------------------------------------------------------------------*/
40 LPSTR
41 NPT_WinRtUtils::W2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT acp)
43 int ret;
45 assert(lpa != NULL);
46 assert(lpw != NULL);
47 if (lpa == NULL || lpw == NULL) return NULL;
49 lpa[0] = '\0';
50 ret = WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);
51 if (ret == 0) {
52 int error = GetLastError();
53 assert(error);
54 return NULL;
56 return lpa;
59 /*----------------------------------------------------------------------
60 | NPT_WinRtUtils::LStrLenW
61 +---------------------------------------------------------------------*/
62 size_t
63 NPT_WinRtUtils::LStrLenW(STRSAFE_LPCWSTR lpw)
65 size_t len = 0;
66 HRESULT result = StringCchLengthW(lpw, STRSAFE_MAX_CCH, &len);
67 if (S_OK == result) {
68 return len;
69 } else {
70 return INT_MAX;