# Define CMDL "HKEY_LOCAL_MACHINE \ Software \ Microsoft \ speech \ Voices" # define spkey_attributes l "attributes" # define spvalue_language l "language" bool cactioncenter: initializesapi () {releasesapi ();
Hresult hr;
HR = m_cpvoice.cocreateinstance (clsid_spvoice); If (hR = s_ OK) {ispobjecttoken * ptoken; // Note: Not a ccomptr! Be careful. ccomptr <ienumspobjecttokens> cpenum; HR = spenumtokens (spcat_voices, l "", l "", & cpenum); If (hR = s_ OK) {bool fsetdefault = false; while (cpenum-> next (1, & ptoken, null) = s_ OK) {// cspdynamicstring dstrdesc; // hR = spgetdescription (ptoken, & dstrdesc ); // If (succeeded (HR) {m_vecisptoken.push_back (ptoken );}
}
Return (m_vecisptoken.size ()> 0 );}}
Return false ;}
Void cactioncenter: releasesapi () {vector <ispobjecttoken *>: iterator it;
For (IT = m_vecisptoken.begin (); it! = M_vecisptoken.end (); ++ it) {(* It)-> release ();}
M_vecisptoken.clear ();}
Void cactioncenter: setvoice (langid lid) {vector <ispobjecttoken *>: iterator it;
Wchar wstrlangid [32] = {0}; swprintf (wstrlangid, l "% x", lid );
For (IT = m_vecisptoken.begin (); it! = M_vecisptoken.end (); ++ it) {ispobjecttoken * ptoken = (* it );
Ispdatakey * pspdatakeyattributes = NULL; hresult hR = ptoken-> openkey (spkey_attributes, & pspdatakeyattributes); If (succeeded (HR) {wchar * wstrlanguageid = NULL; hR = pspdatakeyattributes-> getstringvalue (spvalue_language, (wchar **) & wstrlanguageid); If (succeeded (HR) {If (wcsstr (BSTR) wstrlanguageid, (BSTR) wstrlangid) {m_cpvoice-> setvoice (ptoken); break ;}
}
Pspdatakeyattributes-> release ();}
}}