HSZ InternalDdeCreateStringHandle( DWORD idInst, PVOID psz, int iCodePage) { PCL_INSTANCE_INFO pcii; HSZ hszRet = 0; int cb; WCHAR szw[256]; EnterDDECrit; pcii = ValidateInstance((HANDLE)LongToHandle( idInst )); if (pcii == NULL) { BestSetLastDDEMLError(DMLERR_INVALIDPARAMETER); goto Exit; } switch (iCodePage) { case CP_WINANSI: if (*(LPSTR)psz == '\0') { goto Exit; } hszRet = NORMAL_HSZ_FROM_LATOM(AddAtomA((LPSTR)psz)); break; default: /* * Convert psz to unicode and fall through. */ cb = sizeof(szw) / sizeof(WCHAR); #ifdef LATER MultiByteToWideChar((UINT)iCodePage, MB_PRECOMPOSED, (LPSTR)psz, -1, szw, cb); #endif psz = &szw[0]; case CP_WINUNICODE: if (*(LPWSTR)psz == L'\0') { goto Exit; } hszRet = NORMAL_HSZ_FROM_LATOM(AddAtomW((LPWSTR)psz)); break; } MONHSZ(pcii, hszRet, MH_CREATE); Exit: LeaveDDECrit; return (hszRet); }
static HKEY GetKeyW(LPCWSTR appname, BOOL * closekey, BOOL fCreate) { HKEY key = 0; WCHAR achName[MAX_PATH]; #if !MMPROFILECACHE *closekey = TRUE; #else UINT n; ATOM atm; *closekey = FALSE; // // See if we have already used this key // atm = FindAtomW(appname); if (atm != 0) { // Atom exists... search the table for it. for (n=0; n<keyscached; ++n) { if (akeyatoms[n] == atm) { DPF2(("(W)Found existing key for %ls\n", appname)); return ahkey[n]; } } } DPF2(("(W)No key found for %ls\n", appname)); #endif StringCchCopyW(achName, MAX_PATH, KEYNAME ); StrCchCatW(achName, MAX_PATH, appname); if ((!fCreate && RegOpenKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS) || (fCreate && RegCreateKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS)) { #if MMPROFILECACHE if (keyscached < KEYSCACHED && (atm = AddAtomW(appname))) { // Add this key to the cache array akeyatoms[keyscached] = atm; ahkey[keyscached] = key; DPF1(("Adding key %ls to cache array in position %d\n", appname, keyscached)); ++keyscached; } else { DPF2(("Not adding key to cache array\n")); *closekey = TRUE; } #endif } return(key); }
/*********************************************************************** * UXTHEME_SetWindowProperty * * I'm using atoms as there may be large numbers of duplicated strings * and they do the work of keeping memory down as a cause of that quite nicely */ static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue) { ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp)); if(oldValue) DeleteAtom(oldValue); if(pszValue) { ATOM atValue = AddAtomW(pszValue); if(!atValue || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) { HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); if(atValue) DeleteAtom(atValue); return hr; } } return S_OK; }
static void test_local_error_handling(void) { char buffer[260]; WCHAR bufferW[260]; int i; memset( buffer, 'a', 256 ); buffer[256] = 0; ok( !AddAtomA(buffer), "add succeeded\n" ); ok( !FindAtomA(buffer), "find succeeded\n" ); if (unicode_OS) { for (i = 0; i < 256; i++) bufferW[i] = 'b'; bufferW[256] = 0; ok( !AddAtomW(bufferW), "add succeeded\n" ); ok( !FindAtomW(bufferW), "find succeeded\n" ); } }
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()); } }
static void test_local_add_atom(void) { ATOM atom, w_atom; INT_PTR i; SetLastError( 0xdeadbeef ); atom = AddAtomA( "foobar" ); ok( atom >= 0xc000, "bad atom id %x\n", atom ); ok( GetLastError() == 0xdeadbeef, "AddAtomA set last error\n" ); /* Verify that it can be found (or not) appropriately */ ok( FindAtomA( "foobar" ) == atom, "could not find atom foobar\n" ); ok( FindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" ); ok( !FindAtomA( "_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 = AddAtomW( 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, "AddAtomW set last error\n" ); } /* Verify that it can be found (or not) appropriately via unicode name */ if (unicode_OS) { ok( FindAtomW( foobarW ) == atom, "could not find atom foobar\n" ); ok( FindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR\n" ); ok( !FindAtomW( _foobarW ), "found _foobar\n" ); } /* Test integer atoms * (0x0001 .. 0xbfff) should be valid; * (0xc000 .. 0xffff) should be invalid */ SetLastError( 0xdeadbeef ); ok( AddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" ); if (unicode_OS) { SetLastError( 0xdeadbeef ); ok( AddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "succeeded to add atom 0\n" ); } SetLastError( 0xdeadbeef ); for (i = 1; i <= 0xbfff; i++) { SetLastError( 0xdeadbeef ); ok( AddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef, "failed to add atom %lx\n", i ); if (unicode_OS) { SetLastError( 0xdeadbeef ); ok( AddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef, "failed to add atom %lx\n", i ); } } for (i = 0xc000; i <= 0xffff; i++) { ok( !AddAtomA((LPCSTR)i), "succeeded adding %lx\n", i ); if (unicode_OS) ok( !AddAtomW((LPCWSTR)i), "succeeded adding %lx\n", i ); } }