Exemple #1
0
khm_int32 KHMAPI
addr_list_toString(const void *d, khm_size cb_d,
		   wchar_t *buf, khm_size *pcb_buf,
		   khm_int32 flags)
{
    HostAddresses as;
    size_t len;
    size_t i;

    wchar_t wstr[2048] = L"";
    wchar_t *wstr_d = &wstr[0];
    khm_size cch_wstr = ARRAYLENGTH(wstr);

    if ( decode_HostAddresses((const unsigned char *) d, cb_d, &as, &len) ) {
	assert(FALSE);
	return KHM_ERROR_INVALID_PARAM;
    }

    for (i=0; i < as.len; i++) {
	char buf[1024];
	wchar_t wbuf[1024];

	len = sizeof(buf);
	if (krb5_print_address(&as.val[i], buf, sizeof(buf), &len)) {
	    assert(FALSE);
	    continue;
	}

	AnsiStrToUnicode(wbuf, sizeof(wbuf), buf);
	if (FAILED(StringCchCatEx(wstr_d, cch_wstr, wbuf, &wstr_d, &cch_wstr,
				  STRSAFE_NO_TRUNCATION))) {
	    assert(FALSE);
	    continue;
	}

	if (i + 1 < as.len) {
	    if (FAILED(StringCchCatEx(wstr_d, cch_wstr, L",", &wstr_d, &cch_wstr,
				      STRSAFE_NO_TRUNCATION))) {
		assert(FALSE);
		continue;
	    }
	}
    }

    len = (ARRAYLENGTH(wstr) - cch_wstr) * sizeof(wchar_t);

    if (buf == NULL || *pcb_buf < len) {
	*pcb_buf = len;
	return KHM_ERROR_TOO_LONG;
    }

    StringCbCopy(buf, *pcb_buf, wstr);
    *pcb_buf = len;
    free_HostAddresses(&as);

    return KHM_ERROR_SUCCESS;
}
HRESULT GetIDListName(IShellItem *psi, PWSTR *ppsz)
{
    *ppsz = NULL;
    HRESULT hr = E_FAIL;

    WCHAR szFullName[2048];
    szFullName[0] = 0;
    PWSTR pszOutput = szFullName;
    size_t cchOutput = ARRAYSIZE(szFullName);

    CItemIterator itemIterator(psi);
    while (itemIterator.MoveNext())
    {
        IShellItem2 *psi;
        hr = itemIterator.GetCurrent(IID_PPV_ARGS(&psi));
        if (SUCCEEDED(hr))
        {
            PWSTR pszName;
            hr = psi->GetDisplayName(SIGDN_PARENTRELATIVE, &pszName);
            if (SUCCEEDED(hr))
            {
                // Ignore errors, this is for debugging only
                StringCchCatEx(pszOutput, cchOutput, L"[", &pszOutput, &cchOutput, 0);
                StringCchCatEx(pszOutput, cchOutput, pszName, &pszOutput, &cchOutput, 0);
                StringCchCatEx(pszOutput, cchOutput, L"]", &pszOutput, &cchOutput, 0);
                CoTaskMemFree(pszName);
            }
            psi->Release();
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = SHStrDup(szFullName, ppsz);
    }
    return hr;
}