hello, chiming in for a couple of comments.
On 21 August 2015 at 07:22, Thiago Macieira <[email protected]> wrote: > On Wednesday 19 August 2015 00:57:20 Claudiu Olteanu wrote: <snip> > >> I tried as well to replace the WSAStringToAddressA with >> WSAStringToAddressW but I had to represent the >> address as a wchar_t* and and when I wanted to use >> mbstowcs_s for conversion (from const char* to wchar_t*) >> the compiler couldn't find the declaration to the method >> (even though I included the stdlib header). After some >> failed attempts I gave up :). > Like I said, never, ever use <wchar.h> functions. Those are braindead in > design, at least compared to Qt's equivalents. > > Before I go into this, let me say that the patches are fine and Dirk can apply > them as-is. There's no need to change further. Mingw doesn't have an exact port of all of the _s functions in MSVC - some of them are present in stdlib_s.h, including mbstowcs_s. i see it the following way - the "W" variants is only there for compatibility with the rest of the WIN32. the address itself *should be* ASCII-US, therefore the "W" API is not needed here and WSAStringToAddressA/WSAStringToAddressA can be used instead (?). > > > With that now said, here's how you can improve. Your code is: > >> + char *address = strdup(devaddr); > [...] >> + if (WSAStringToAddressA(address, >> + AF_BTH, >> + NULL, >> + (LPSOCKADDR) &socketBthAddress, >> + &socketBthAddressBth >> + ) != 0) { >> + > > To use the W function: > > QString address = QString::fromLatin1(devaddr); > if (WSAStringToAddressW(reinterpret_cast<wchar_t*>(address.utf16()), > [...] > > This also solves the strdup() and free() calls. And if the line didn't get too > long, you could do everything in one line. > i don't think WSAStringToAddressA will modify the input string unless explicitly stated in the documentation. the WIN32 API seems to be consistent in terms of input/output ownership - i.e. "i will only modify the output targets you give me and not touch your input targets". i'm pretty sure this should work: WSAStringToAddressA((char *)devaddr... lubomir -- _______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
