示例#1
0
文件: atom.c 项目: Barrell/wine
/***********************************************************************
 *           GetAtomNameA   (KERNEL32.@)
 *
 * Get a copy of the string associated with an atom.
 *
 * RETURNS
 *	Success: The length of the returned string in characters.
 *	Failure: 0.
 */
UINT WINAPI GetAtomNameA(
              ATOM atom,    /* [in]  Atom */
              LPSTR buffer, /* [out] Pointer to string for atom string */
              INT count)    /* [in]  Size of buffer */
{
    WCHAR       tmpW[MAX_ATOM_LEN + 1];
    UINT        wlen, len = 0, c;

    if (count <= 0) SetLastError( ERROR_MORE_DATA );
    else if ((wlen = GetAtomNameW( atom, tmpW, MAX_ATOM_LEN + 1 )))
    {
        char    tmp[MAX_ATOM_LEN + 1];

        len = WideCharToMultiByte( CP_ACP, 0, tmpW, wlen, tmp, MAX_ATOM_LEN + 1, NULL, NULL );
        c = min(len, count - 1);
        memcpy(buffer, tmp, c);
        buffer[c] = '\0';
        if (len >= count)
        {
            len = c;
            SetLastError( ERROR_MORE_DATA );
        }
    }
    return len;
}
示例#2
0
static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
{
    ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
    if(atValue) {
        if(GetAtomNameW(atValue, pszBuffer, dwLen))
            return pszBuffer;
        TRACE("property defined, but unable to get value\n");
    }
    return NULL;
}
示例#3
0
文件: atom.c 项目: AmesianX/RosWine
static void test_local_get_atom_name(void)
{
    char buf[10], in[257], out[257];
    WCHAR bufW[10], inW[257], outW[257];
    int i;
    UINT len;
    static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};

    ATOM atom = AddAtomA( "foobar" );

    /* Get the name of the atom we added above */
    memset( buf, '.', sizeof(buf) );
    len = GetAtomNameA( atom, buf, 10 );
    ok( len == strlen("foobar"), "bad length %d\n", len );
    ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents\n" );

    /* Repeat, unicode-style */
    if (unicode_OS)
    {
        for (i = 0; i < 10; i++) bufW[i] = '.';
        SetLastError( 0xdeadbeef );
        len = GetAtomNameW( atom, bufW, 10 );
        ok( len && GetLastError() == 0xdeadbeef, "GetAtomNameW failed\n" );
        ok( len == lstrlenW(foobarW), "bad length %d\n", len );
        ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
    }

    /* Get the name of the atom we added above */
    memset( buf, '.', sizeof(buf) );
    len = GetAtomNameA( atom, buf, 6 );
    ok( len == 5, "bad length %d\n", len );
    ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n" );
 
    /* Repeat, unicode-style */
    if (unicode_OS)
    {
        WCHAR resW[] = {'f','o','o','b','a','\0','.','.','.','.'};
        for (i = 0; i < 10; i++) bufW[i] = '.';
        SetLastError( 0xdeadbeef );
        len = GetAtomNameW( atom, bufW, 6 );
        ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
        ok( len == 5, "bad length %d\n", len );
        ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
    }
 
    /* Check error code returns */
    memset(buf, '.', 10);
    ok( !GetAtomNameA( atom, buf,  0 ), "succeeded\n" );
    ok( !memcmp( buf, "..........", 10 ), "should not touch buffer\n" );

    if (unicode_OS)
    {
        static const WCHAR sampleW[] = {'.','.','.','.','.','.','.','.','.','.'};

        for (i = 0; i < 10; i++) bufW[i] = '.';
        ok( !GetAtomNameW( atom, bufW, 0 ), "succeeded\n" );
        ok( !memcmp( bufW, sampleW, sizeof(sampleW) ), "should not touch buffer\n" );
    }

    /* Test integer atoms */
    for (i = 0; i <= 0xbfff; i++)
    {
        memset( buf, 'a', 10 );
        len = GetAtomNameA( (ATOM)i, buf, 10 );
        if (i)
        {
            char res[20];
            ok( (len > 1) && (len < 7), "bad length %d for %s\n", len, buf );
            sprintf( res, "#%d", i );
            memset( res + strlen(res) + 1, 'a', 10 );
            ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
        }
        else
            ok( !len, "bad length %d\n", len );

        len = GetAtomNameA( (ATOM)i, buf, 1);
        ok(!len, "succeed with %u for %u\n", len, i);

        /* ERROR_MORE_DATA is on nt3.51 sp5 */
        if (i)
            ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
               GetLastError() == ERROR_MORE_DATA,
               "wrong error conditions %u for %u\n", GetLastError(), i);
        else
            ok(GetLastError() == ERROR_INVALID_PARAMETER ||
               GetLastError() == ERROR_MORE_DATA,
               "wrong error conditions %u for %u\n", GetLastError(), i);
    }
    /* test string limits & overflow */
    do_initA(in, "abcdefghij", 255);
    atom = AddAtomA(in);
    ok(atom, "couldn't add atom for %s\n", in);
    len = GetAtomNameA(atom, out, sizeof(out));
    ok(len == 255, "length mismatch (%u instead of 255)\n", len);
    for (i = 0; i < 255; i++)
    {
        ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
    }
    ok(out[255] == '\0', "wrong end of string\n");
    memset(out, '.', sizeof(out));
    len = GetAtomNameA(atom, out, 10);
    ok(len == 9, "succeeded %d\n", len);
    for (i = 0; i < 9; i++)
    {
        ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
    }
    ok(out[9] == '\0', "wrong end of string\n");
    ok(out[10] == '.', "buffer overwrite\n");
    do_initA(in, "abcdefghij", 256);
    atom = AddAtomA(in);
    ok(!atom, "succeeded\n");

    /* ERROR_MORE_DATA is on nt3.51 sp5 */
    ok(GetLastError() == ERROR_INVALID_PARAMETER ||
       GetLastError() == ERROR_MORE_DATA,
       "wrong error code (%u)\n", GetLastError());

    if (unicode_OS)
    {
        /* test integral atoms */
        for (i = 0; i <= 0xbfff; i++)
        {
            memset(outW, 'a', sizeof(outW));
            len = GetAtomNameW( (ATOM)i, outW, 10 );
            if (i)
            {
                WCHAR res[20];
                
                ok( (len > 1) && (len < 7), "bad length %d\n", len );
                wsprintfW( res, integfmt, i );
                memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
                ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
            }
            else
                ok( !len, "bad length %d\n", len );

            len = GetAtomNameW( (ATOM)i, outW, 1);
            ok(!len, "succeed with %u for %u\n", len, i);

            /* ERROR_MORE_DATA is on nt3.51 sp5 */
            ok(GetLastError() == ERROR_MORE_DATA ||
               GetLastError() == (i ? ERROR_INSUFFICIENT_BUFFER : ERROR_INVALID_PARAMETER),
               "wrong error conditions %u for %u\n", GetLastError(), i);
        }
        do_initW(inW, "abcdefghij", 255);
        atom = AddAtomW(inW);
        ok(atom, "couldn't add atom for %s\n", in);
        len = GetAtomNameW(atom, outW, sizeof(outW)/sizeof(outW[0]));
        ok(len == 255, "length mismatch (%u instead of 255)\n", len);
        for (i = 0; i < 255; i++)
        {
            ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
        }
        ok(outW[255] == '\0', "wrong end of string\n");
        memset(outW, '.', sizeof(outW));
        len = GetAtomNameW(atom, outW, 10);
        ok(len == 9, "succeeded %d\n", len);
        for (i = 0; i < 9; i++)
        {
            ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
        }
        ok(outW[9] == '\0', "wrong end of string\n");
        ok(outW[10] == DOUBLE('.'), "buffer overwrite\n");
        do_initW(inW, "abcdefghij", 256);
        atom = AddAtomW(inW);
        ok(!atom, "succeeded\n");

        /* ERROR_MORE_DATA is on nt3.51 sp5 */
        ok(GetLastError() == ERROR_INVALID_PARAMETER ||
           GetLastError() == ERROR_MORE_DATA,
           "wrong error code (%u)\n", GetLastError());
    }
}
示例#4
0
文件: hsz.c 项目: conioh/os-design
DWORD InternalDdeQueryString(
DWORD idInst,
HSZ hsz,
PVOID psz,
DWORD cbMax,
INT iCodePage)
{
    PCL_INSTANCE_INFO pcii;
    DWORD dwRet = 0;
    WCHAR szw[256];
// BOOL fDefUsed; // LATER

    EnterDDECrit;

    pcii = ValidateInstance((HANDLE)LongToHandle( idInst ));
    if (pcii == NULL) {
        BestSetLastDDEMLError(DMLERR_INVALIDPARAMETER);
        goto Exit;
    }

    if (ValidateHSZ(hsz) == HSZT_INVALID) {
        SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER);
        goto Exit;
    }

    if (LATOM_FROM_HSZ(hsz) == 0) {
        if (iCodePage == CP_WINUNICODE) {
            if (psz != NULL) {
                *(LPWSTR)psz = L'\0';
            }
            dwRet = sizeof(WCHAR);
            goto Exit;
        } else {
            if (psz != NULL) {
                *(LPSTR)psz = '\0';
            }
            dwRet = sizeof(CHAR);
            goto Exit;
        }
    }

    if (psz == NULL) {
        cbMax = sizeof(szw);
        psz = (PVOID)szw;
    }

    switch (iCodePage) {
    case CP_WINANSI:
        dwRet = GetAtomNameA(LATOM_FROM_HSZ(hsz), psz, cbMax);
        break;

    default:
        dwRet = GetAtomNameW(LATOM_FROM_HSZ(hsz), (LPWSTR)psz, cbMax / sizeof(WCHAR));
        if (iCodePage != CP_WINUNICODE) {

            /*
             * convert psz to the appropriate codepage and count the
             * characters(ie BYTES for DBCS!) to alter dwRet.
             */
#ifdef LATER
            // Does this routine work in place? (i.e. input and output buffer the same).
            WideCharToMultiByte((UINT)iCodePage, 0, szw,
                    sizeof(szw) /  sizeof(WCHAR),
                    (LPSTR)psz, cbMax, NULL, &fDefUsed);
#endif
            dwRet = cbMax + 1;
        }
        break;
    }

Exit:
    LeaveDDECrit;
    return (dwRet);
}