Re: [PATCH] winecfg: Add trackbar to set screen resolution in graphics tab (try 2)
Nigel Liang <ncliang(a)gmail.com> writes:
+/* Utility functions to convert between WCHAR and long */ +long wcstolong(WCHAR * wcs) +{ + int i; + long lRet = 0; + BOOL bNeg = FALSE; + + for (i = 0; wcs[i] != '\0'; i++) { + if (i == 0 && wcs[i] == '-') { + bNeg = TRUE; + continue; + } + + lRet = lRet * 10 + (wcs[i] - '0'); + } + return (bNeg ? -lRet : lRet); +} + +WCHAR *longtow(long num, WCHAR *wcs) +{ + static const WCHAR str[] = { '%', 'l', 'd', 0 }; + wsprintfW(wcs, str, num); + return wcs; +}
That's ugly. You should avoid using long if not really necessary, since it doesn't have the same size in MSVC. You shouldn't name a function wcs something since that's what wchar_t functions use. In any case we already have atoiW for that purpose. Also I don't think wrapping wsprintf is needed. -- Alexandre Julliard julliard(a)winehq.org
On 7/30/07, Alexandre Julliard <julliard(a)winehq.org> wrote:
Nigel Liang <ncliang(a)gmail.com> writes:
+/* Utility functions to convert between WCHAR and long */ +long wcstolong(WCHAR * wcs) +{ + int i; + long lRet = 0; + BOOL bNeg = FALSE; + + for (i = 0; wcs[i] != '\0'; i++) { + if (i == 0 && wcs[i] == '-') { + bNeg = TRUE; + continue; + } + + lRet = lRet * 10 + (wcs[i] - '0'); + } + return (bNeg ? -lRet : lRet); +} + +WCHAR *longtow(long num, WCHAR *wcs) +{ + static const WCHAR str[] = { '%', 'l', 'd', 0 }; + wsprintfW(wcs, str, num); + return wcs; +}
That's ugly. You should avoid using long if not really necessary, since it doesn't have the same size in MSVC. You shouldn't name a function wcs something since that's what wchar_t functions use. In any case we already have atoiW for that purpose. Also I don't think wrapping wsprintf is needed.
-- Alexandre Julliard julliard(a)winehq.org
Yeah, I did not like those either. The reason that I used them is because trying to use the _ltow and wcstol functions from msvcrt/stdlib.h caused a bunch of conflicting type errors. I'll get rid of them.... -Nigel
participants (2)
-
Alexandre Julliard -
Nigel Liang