[PATCH] odbccp32: Implement SQLConfigDataSource/W

Nikolay Sivov nsivov at codeweavers.com
Mon Oct 22 04:10:33 CDT 2018


On 10/22/2018 07:54 AM, Alistair Leslie-Hughes wrote:

> +static inline WCHAR *heap_attrdupAtoW(const char *str)
> +{
> +    LPWSTR ret = NULL;
> +
> +    if(str)
> +    {
> +        DWORD size = 0, len;
> +        const char *p;
> +        LPWSTR current = NULL;

'current' doesn't have to be initialized. Please use space after 'if'.

> +
> +        for (p = str; *p; p += lstrlenA(p) + 1)
> +        {
> +            len = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
> +            size += len;
> +        }
> +
> +        current = ret = heap_alloc_zero( (size+1)*sizeof(WCHAR));
> +        for (p = str; *p; p += lstrlenA(p) + 1)
> +        {
> +            len = MultiByteToWideChar(CP_ACP, 0, p, -1, current, size);
> +            current += len;
> +            size -= len;
> +        }

I think it's enough to zero ret[size] only.

> +    }
> +    return ret;
> +}
> +static BOOL call_ConfigDNS(HANDLE mod, HWND hwnd, WORD request, LPCSTR driverA, LPCSTR attributesA, LPCWSTR driverW, LPCWSTR attributesW)
> +{

Typo.

> +BOOL WINAPI SQLConfigDataSource(HWND hwndParent, WORD fRequest,
> +               LPCSTR lpszDriver, LPCSTR lpszAttributes)
> +{
> +    HMODULE hmod;
> +    BOOL ret = FALSE;
> +    WCHAR *driverW;
> +
> +    TRACE("%p, %d, %s, %s\n", hwndParent, fRequest, debugstr_a(lpszDriver), debugstr_a(lpszAttributes));
> +
> +    if(TRACE_ON(odbc))
> +    {
> +        const char *p;
> +        for (p = lpszAttributes; *p; p += lstrlenA(p) + 1)
> +            TRACE("%s\n", debugstr_a(p));
> +    }
> +
> +    clear_errors();
> +
> +    driverW = heap_strdupAtoW(lpszDriver);
> +    if(!driverW)
> +    {
> +        push_error(ODBC_ERROR_OUT_OF_MEM, odbc_error_out_of_mem);
> +        return FALSE;
> +    }
> +
> +    hmod = load_config_driver(driverW);
> +    if(!hmod)
> +    {
> +        heap_free(driverW);
> +        return FALSE;
> +    }
> +
> +    ret = call_ConfigDNS (hmod, hwndParent, fRequest, lpszDriver, lpszAttributes, driverW, NULL);
> +    heap_free(driverW);
> +
> +    FreeLibrary(hmod);
> +
> +    return ret;
> +}
Can you call W variant from this one? Same for formatting, since it's a 
new piece it's an opportunity to clean up argument names.

Have you tested that both calls end up calling ConfigDSNW if it's 
available, instead of actually matching argument types and calling 
ConfigDSN or ConfigDSNW.



More information about the wine-devel mailing list