Exemple #1
0
ESTATUS main_AddNullTerminatedAtomAndVerifyW(LPWSTR pswzBuffer, ATOM *ptAtom)
{
	ATOM tAtom = 0;
	ESTATUS eReturn = ESTATUS_INVALID;
	LPWSTR pswzCheckBuffer = NULL;
	DWORD cbCheckBuffer = 0;
	UINT uiRet = 0;
	HMODULE hUser32 = NULL;
	BOOL bWasAtomWrittenSuccessfully = FALSE;

	// If user32.dll is not loaded, the ATOM functions return access denied. For more details see :
	// http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.kernel/2004-03/0851.html
	hUser32 = LoadLibrary(L"user32.dll");

	do
	{
		tAtom = GlobalAddAtomW(pswzBuffer);
		if (0 == tAtom)
		{
			printf("GlobalAddAtomA failed. GLE: 0x%X (%d)\n\n", GetLastError(), GetLastError());
			eReturn = ESTATUS_MAIN_ADDNULLTERMINATEDATOMANDVERIFYW_GLOBALADDATOMW_FAILED;
			goto lblCleanup;
		}

		eReturn = main_WasAtomWrittenSuccessfully(tAtom, pswzBuffer, &bWasAtomWrittenSuccessfully);
		if (ESTATUS_FAILED(eReturn))
		{
			goto lblCleanup;
		}

		if (FALSE != bWasAtomWrittenSuccessfully)
		{
			break;
		}
		
		for (int i = 0; i < 0x2; i++)
		{
			SetLastError(ERROR_SUCCESS);
			GlobalDeleteAtom(tAtom);
			if (ERROR_SUCCESS != GetLastError())
			{
				eReturn = ESTATUS_MAIN_ADDNULLTERMINATEDATOMANDVERIFYW_GLOBALDELETEATOM_FAILED;
				goto lblCleanup;
			}
		}
	} while (FALSE == bWasAtomWrittenSuccessfully);
	

	eReturn = ESTATUS_SUCCESS;
	*ptAtom = tAtom;

lblCleanup:
	return eReturn;

}
Exemple #2
0
/***********************************************************************
 *      UXTHEME_InitSystem
 */
void UXTHEME_InitSystem(HINSTANCE hInst)
{
    static const WCHAR szWindowTheme[] = {
        'u','x','_','t','h','e','m','e','\0'
    };
    static const WCHAR szSubAppName[] = {
        'u','x','_','s','u','b','a','p','p','\0'
    };
    static const WCHAR szSubIdList[] = {
        'u','x','_','s','u','b','i','d','l','s','t','\0'
    };
    static const WCHAR szDialogThemeEnabled[] = {
        'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
    };

    hDllInst = hInst;

    atWindowTheme        = GlobalAddAtomW(szWindowTheme);
    atSubAppName         = GlobalAddAtomW(szSubAppName);
    atSubIdList          = GlobalAddAtomW(szSubIdList);
    atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
    atWndContrext        = GlobalAddAtomW(L"ux_WndContext");
}
Exemple #3
0
/*
 * @implemented
 */
BOOL WINAPI
SetPropW(HWND hWnd, LPCWSTR lpString, HANDLE hData)
{
  ATOM Atom;
  if (HIWORD(lpString))
    {
      Atom = GlobalAddAtomW(lpString);
    }
  else
    {
      Atom = LOWORD((DWORD_PTR)lpString);
    }

  return(NtUserSetProp(hWnd, Atom, hData));
}
Exemple #4
0
static void test_error_handling(void)
{
    char buffer[260];
    WCHAR bufferW[260];
    int i;

    memset( buffer, 'a', 256 );
    buffer[256] = 0;
    ok( !GlobalAddAtomA(buffer), "add succeeded\n" );
    ok( !GlobalFindAtomA(buffer), "find succeeded\n" );

    if (unicode_OS)
    {
        for (i = 0; i < 256; i++) bufferW[i] = 'b';
        bufferW[256] = 0;
        ok( !GlobalAddAtomW(bufferW), "add succeeded\n" );
        ok( !GlobalFindAtomW(bufferW), "find succeeded\n" );
    }
}
Exemple #5
0
BOOL init_bosskey(LPWNDINFO pInfo)
{
	WCHAR	win_titiles[BUFSIZE+1];
	while ( !pInfo->hFF )                 /* 等待主窗口并获取句柄 */
	{
		HWND hwnd_pre = FindWindowExW( NULL, NULL, L"MozillaWindowClass", NULL );
		while (NULL != hwnd_pre)
		{
			int n = GetWindowTextW(hwnd_pre, win_titiles, BUFSIZE);
			if ( n>0 && n < BUFSIZE)
			{
				win_titiles[n] = L'\0';
				if (  stristrW(win_titiles, L"- Mozilla Thunderbird") )
				{
					/* 获取thunderbird窗体句柄 */
					pInfo->hFF = is_thunderbird()?hwnd_pre:NULL;
				}
				else
				{
					/* 获取firefox窗体句柄 */
					pInfo->hFF = is_browser()?hwnd_pre:NULL;
				}
			}
			if (pInfo->hFF)
			{
				break;
			}
			hwnd_pre = FindWindowExW(NULL, hwnd_pre, L"MozillaWindowClass", NULL);
		}
		Sleep(800);
	}
	if ( pInfo->hFF )
	{
		WCHAR atom_str[VALUE_LEN+1] = {0};
		GetModuleFileNameW(NULL,atom_str,VALUE_LEN);
		GetWindowThreadProcessId(pInfo->hFF, &pInfo->pFF);
		pInfo->atom_str = GlobalAddAtomW(atom_str)-0xC000;
	}
	return RegisterHotKey(NULL, pInfo->atom_str, pInfo->key_mod, pInfo->key_vk);
}
Exemple #6
0
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);

    switch (fdwReason) {
	case DLL_PROCESS_ATTACH:
            DisableThreadLibraryCalls(hinstDLL);

            COMCTL32_hModule = hinstDLL;

            /* add global subclassing atom (used by 'tooltip' and 'updown') */
            COMCTL32_wSubclass = (LPWSTR)(DWORD_PTR)GlobalAddAtomW (strCC32SubclassInfo);
            TRACE("Subclassing atom added: %p\n", COMCTL32_wSubclass);

            /* create local pattern brush */
            COMCTL32_hPattern55AABitmap = CreateBitmap (8, 8, 1, 1, wPattern55AA);
            COMCTL32_hPattern55AABrush = CreatePatternBrush (COMCTL32_hPattern55AABitmap);

	    /* Get all the colors at DLL load */
	    COMCTL32_RefreshSysColors();

            /* like comctl32 5.82+ register all the common control classes */
            ANIMATE_Register ();
            COMBOEX_Register ();
            DATETIME_Register ();
            FLATSB_Register ();
            HEADER_Register ();
            HOTKEY_Register ();
            IPADDRESS_Register ();
            LISTVIEW_Register ();
            MONTHCAL_Register ();
            NATIVEFONT_Register ();
            PAGER_Register ();
            PROGRESS_Register ();
            REBAR_Register ();
            STATUS_Register ();
            SYSLINK_Register ();
            TAB_Register ();
            TOOLBAR_Register ();
            TOOLTIPS_Register ();
            TRACKBAR_Register ();
            TREEVIEW_Register ();
            UPDOWN_Register ();

            /* subclass user32 controls */
            THEMING_Initialize ();
            break;

	case DLL_PROCESS_DETACH:
            if (lpvReserved) break;
            /* clean up subclassing */
            THEMING_Uninitialize();

            /* unregister all common control classes */
            ANIMATE_Unregister ();
            COMBOEX_Unregister ();
            DATETIME_Unregister ();
            FLATSB_Unregister ();
            HEADER_Unregister ();
            HOTKEY_Unregister ();
            IPADDRESS_Unregister ();
            LISTVIEW_Unregister ();
            MONTHCAL_Unregister ();
            NATIVEFONT_Unregister ();
            PAGER_Unregister ();
            PROGRESS_Unregister ();
            REBAR_Unregister ();
            STATUS_Unregister ();
            SYSLINK_Unregister ();
            TAB_Unregister ();
            TOOLBAR_Unregister ();
            TOOLTIPS_Unregister ();
            TRACKBAR_Unregister ();
            TREEVIEW_Unregister ();
            UPDOWN_Unregister ();

            /* delete local pattern brush */
            DeleteObject (COMCTL32_hPattern55AABrush);
            DeleteObject (COMCTL32_hPattern55AABitmap);

            /* delete global subclassing atom */
            GlobalDeleteAtom (LOWORD(COMCTL32_wSubclass));
            TRACE("Subclassing atom deleted: %p\n", COMCTL32_wSubclass);
            break;
    }

    return TRUE;
}
Exemple #7
0
static void test_add_atom(void)
{
    ATOM atom, w_atom;
    INT_PTR i;

    SetLastError( 0xdeadbeef );
    atom = GlobalAddAtomA( "foobar" );
    ok( atom >= 0xc000, "bad atom id %x\n", atom );
    ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomA set last error\n" );

    /* Verify that it can be found (or not) appropriately */
    ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
    ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
    ok( !GlobalFindAtomA( "_foobar" ), "found _foobar\n" );

    /* Add the same atom, specifying string as unicode; should
     * find the first one, not add a new one */
    SetLastError( 0xdeadbeef );
    w_atom = GlobalAddAtomW( foobarW );
    if (w_atom && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
        unicode_OS = TRUE;
    else
        trace("WARNING: Unicode atom APIs are not supported on this platform\n");

    if (unicode_OS)
    {
        ok( w_atom == atom, "Unicode atom does not match ASCII\n" );
        ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomW set last error\n" );
    }

    /* Verify that it can be found (or not) appropriately via unicode name */
    if (unicode_OS)
    {
        ok( GlobalFindAtomW( foobarW ) == atom, "could not find atom foobar\n" );
        ok( GlobalFindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" );
        ok( !GlobalFindAtomW( _foobarW ), "found _foobar\n" );
    }

    /* Test integer atoms
     * (0x0001 .. 0xbfff) should be valid;
     * (0xc000 .. 0xffff) should be invalid */

    SetLastError( 0xdeadbeef );
    ok( GlobalAddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
    if (unicode_OS)
    {
        SetLastError( 0xdeadbeef );
        ok( GlobalAddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" );
    }

    SetLastError( 0xdeadbeef );
    for (i = 1; i <= 0xbfff; i++)
    {
        SetLastError( 0xdeadbeef );
        ok( GlobalAddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
            "failed to add atom %lx\n", i );
        if (unicode_OS)
        {
            SetLastError( 0xdeadbeef );
            ok( GlobalAddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
                "failed to add atom %lx\n", i );
        }
    }

    for (i = 0xc000; i <= 0xffff; i++)
    {
        ok( !GlobalAddAtomA((LPCSTR)i), "succeeded adding %lx\n", i );
        if (unicode_OS)
            ok( !GlobalAddAtomW((LPCWSTR)i), "succeeded adding %lx\n", i );
    }
}
Exemple #8
0
static void test_get_atom_name(void)
{
    char buf[10];
    WCHAR bufW[10];
    int i;
    UINT len;
    static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
    char in[257], out[257];
    WCHAR inW[257], outW[257];

    ATOM atom = GlobalAddAtomA( "foobar" );

    /* Get the name of the atom we added above */
    memset( buf, '.', sizeof(buf) );
    len = GlobalGetAtomNameA( 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 = GlobalGetAtomNameW( atom, bufW, 10 );
        ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
        ok( len == lstrlenW(foobarW), "bad length %d\n", len );
        ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
    }

    /* Check error code returns */
    memset(buf, '.', 10);
    ok( !GlobalGetAtomNameA( 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( !GlobalGetAtomNameW( 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 = GlobalGetAtomNameA( (ATOM)i, buf, 10 );
        if (i)
        {
            char res[20];
            ok( (len > 1) && (len < 7), "bad length %d\n", len );
            sprintf( res, "#%d", i );
            memset( res + strlen(res) + 1, 'a', 10 );
            ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
            if (len <= 1 || len >= 7) break;  /* don't bother testing all of them */
        }
        else
            ok( !len, "bad length %d\n", len );

        SetLastError(0xdeadbeef);
        len = GlobalGetAtomNameA( (ATOM)i, buf, 2);
        ok(!len, "bad length %d\n", len);
	ok(GetLastError() == ERROR_MORE_DATA || GetLastError() == ERROR_INVALID_PARAMETER,
            "wrong error conditions %u for %u\n", GetLastError(), i);
    }

    memset( buf, '.', sizeof(buf) );
    len = GlobalGetAtomNameA( atom, buf, 6 );
    ok( len == 0, "bad length %d\n", len );
    ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n");
    if (unicode_OS)
    {
        static const WCHAR resW[] = {'f','o','o','b','a','r','.','.','.','.'};
        for (len = 0; len < 10; len++) bufW[len] = '.';
	SetLastError(0xdeadbeef);
        len = GlobalGetAtomNameW( atom, bufW, 6 );
        ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
        ok( len == lstrlenW(foobarW), "bad length %d\n", len );
        ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
    }

    /* test string limits & overflow */
    do_initA(in, "abcdefghij", 255);
    atom = GlobalAddAtomA(in);
    ok(atom, "couldn't add atom for %s\n", in);
    len = GlobalGetAtomNameA(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));
    SetLastError(0xdeadbeef);
    len = GlobalGetAtomNameA(atom, out, 10);
    ok(!len, "bad length %d\n", len);
    ok(GetLastError() == ERROR_MORE_DATA, "wrong error code (%u instead of %u)\n", GetLastError(), ERROR_MORE_DATA);
    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] == '.', "wrote after end of buf\n");
    do_initA(in, "abcdefghij", 256);
    atom = GlobalAddAtomA(in);
    ok(!atom, "succeeded\n");
    if (unicode_OS)
    {
        /* test integral atoms */
        for (i = 0; i <= 0xbfff; i++)
        {
            memset(outW, 'a', sizeof(outW));
            len = GlobalGetAtomNameW( (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 );
                if (len <= 1 || len >= 7) break;  /* don't bother testing all of them */
            }
            else
                ok( !len, "bad length %d\n", len );

            memset(outW, '.', sizeof(outW));
            SetLastError(0xdeadbeef);
            len = GlobalGetAtomNameW( (ATOM)i, outW, 1);
            if (i)
            {
                /* len == 0 with ERROR_MORE_DATA is on NT3.51 */
                ok(len == 1 || (len == 0 && GetLastError() == ERROR_MORE_DATA),
                         "0x%04x: got %u with %d (expected '1' or '0' with "
                         "ERROR_MORE_DATA)\n", i, len, GetLastError());
                ok(outW[1] == DOUBLE('.'), "buffer overwrite\n");
            }
            else ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "0 badly handled\n");
        }

        do_initW(inW, "abcdefghij", 255);
        atom = GlobalAddAtomW(inW);
        ok(atom, "couldn't add atom for %s\n", in);
        len = GlobalGetAtomNameW(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 = GlobalGetAtomNameW(atom, outW, 10);
        ok(len == 10, "succeeded\n");
        for (i = 0; i < 10; i++)
        {
            ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
        }
        ok(outW[10] == DOUBLE('.'), "wrote after end of buf\n");
        do_initW(inW, "abcdefghij", 256);
        atom = GlobalAddAtomW(inW);
        ok(!atom, "succeeded\n");
        ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code\n");
    }
}
Exemple #9
0
LRESULT WINAPI LresultFromObject( REFIID riid, WPARAM wParam, LPUNKNOWN pAcc )
{
    static const WCHAR atom_fmt[] = {'%','0','8','x',':','%','0','8','x',':','%','0','8','x',0};
    static const LARGE_INTEGER seek_zero = {{0}};

    WCHAR atom_str[sizeof(lresult_atom_prefix)/sizeof(WCHAR)+3*8+3];
    IStream *stream;
    HANDLE mapping;
    STATSTG stat;
    HRESULT hr;
    ATOM atom;
    void *view;

    TRACE("%s %ld %p\n", debugstr_guid(riid), wParam, pAcc);

    if(wParam)
        FIXME("unsupported wParam = %lx\n", wParam);

    if(!pAcc)
        return E_INVALIDARG;

    hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
    if(FAILED(hr))
        return hr;

    hr = CoMarshalInterface(stream, riid, pAcc, MSHCTX_LOCAL, NULL, MSHLFLAGS_NORMAL);
    if(FAILED(hr)) {
        IStream_Release(stream);
        return hr;
    }

    hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
    if(FAILED(hr)) {
        IStream_Release(stream);
        return hr;
    }

    hr = IStream_Stat(stream, &stat, STATFLAG_NONAME);
    if(FAILED(hr)) {
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;
    }else if(stat.cbSize.u.HighPart) {
        FIXME("stream size to big\n");
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_NOTIMPL;
    }

    mapping = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
            stat.cbSize.u.HighPart, stat.cbSize.u.LowPart, NULL);
    if(!mapping) {
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;
    }

    view = MapViewOfFile(mapping, FILE_MAP_WRITE, 0, 0, 0);
    if(!view) {
        CloseHandle(mapping);
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_FAIL;
    }

    hr = IStream_Read(stream, view, stat.cbSize.u.LowPart, NULL);
    UnmapViewOfFile(view);
    if(FAILED(hr)) {
        CloseHandle(mapping);
        hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
        if(SUCCEEDED(hr))
            CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;

    }

    memcpy(atom_str, lresult_atom_prefix, sizeof(lresult_atom_prefix));
    sprintfW(atom_str+sizeof(lresult_atom_prefix)/sizeof(WCHAR),
             atom_fmt, GetCurrentProcessId(), HandleToUlong(mapping), stat.cbSize.u.LowPart);
    atom = GlobalAddAtomW(atom_str);
    if(!atom) {
        CloseHandle(mapping);
        hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
        if(SUCCEEDED(hr))
            CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_FAIL;
    }

    IStream_Release(stream);
    return atom;
}