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); }
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_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 ); } }