#define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #define NOMINMAX #include #include #include #include #include long WriteSpellerKeys( std::string buf, std::set langs, std::string dll, std::string lex) { HKEY key; LONG rv = 0; std::string path("Software\\Microsoft\\Shared Tools\\Proofing Tools\\1.0\\Override\\"); for (std::set::iterator lang = langs.begin(); lang != langs.end(); ++lang) { std::cerr << "path + lang" << path + *lang << std::endl; if ((rv = RegCreateKeyExA(HKEY_CURRENT_USER, (path + *lang).c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &key, 0)) != ERROR_SUCCESS) { std::cerr << "Error: Could not create HKCU" << path << *lang << ": " << rv << std::endl; return rv; } std::string data; if (data.assign(buf + dll).empty() || (rv = RegSetValueExA(key, "DLL", 0, REG_SZ, reinterpret_cast(data.c_str()), data.size()+1)) != ERROR_SUCCESS) { std::cerr << "Error: Could not write DLL: " << rv << std::endl; return rv; } if (data.assign(buf + lex).empty() || (rv = RegSetValueExA(key, "LEX", 0, REG_SZ, reinterpret_cast(data.c_str()), data.size()+1)) != ERROR_SUCCESS) { std::cerr << "Error: Could not write LEX: " << rv << std::endl; return rv; } RegCloseKey(key); } return rv; } int main(int argc, char *argv[]) { std::string buf(1024, 0); uint32_t len = buf.size(); HKEY key; LONG rv = 0; std::string activesetup("Software\\Microsoft\\Active Setup\\Installed Components\\{"); // This GUID is the same GUID as in the SmeSpellReg component activesetup += std::string("8c96bac4-371c-4635-91c6-b2d9ecd45084"); activesetup += std::string("}"); if ((rv = RegOpenKeyExA(HKEY_LOCAL_MACHINE, activesetup.c_str(), 0, KEY_READ|KEY_WOW64_32KEY, &key)) != ERROR_SUCCESS && (rv = RegOpenKeyExA(HKEY_LOCAL_MACHINE, activesetup.c_str(), 0, KEY_READ|KEY_WOW64_64KEY, &key)) != ERROR_SUCCESS) { std::cerr << "Error: Could not open HKLM\\" << activesetup << " for reading: " << rv << std::endl; return -rv; } if ((rv = RegQueryValueExA(key, "StubPath", 0, 0, reinterpret_cast(&buf[0]), reinterpret_cast(&len))) != ERROR_SUCCESS) { std::cerr << "Error: Could not read StubPath: " << rv << std::endl; return -rv; } RegCloseKey(key); // Strip create_hkcu.exe\0 from the string std::size_t found = buf.find("create"); if (found == std::string::npos) { std::cerr << "Error: invalid content in buffer: " << buf << std::endl; return -found; } buf = buf.substr(0, found); std::set langs; langs.insert("se-FI"); langs.insert("se-NO"); langs.insert("se-SE"); WriteSpellerKeys(buf, langs, "mssp3samiNorthern-NO.dll", "mssp3samiNorthern.lex"); langs.clear(); langs.insert("sma-NO"); langs.insert("sma-SE"); WriteSpellerKeys(buf, langs, "mssp3samiSouthern-SE.dll", "mssp3samiSout.lex"); langs.clear(); langs.insert("smj-NO"); langs.insert("smj-SE"); WriteSpellerKeys(buf, langs, "mssp3samiLule-SE.dll", "mssp3samiLule.lex"); langs.clear(); }