summaryCalled when I am running in NVDA initialize function, returns the Already initialized, then prism doesn't seem to recognize NVDA back end. When I use the zdsr backend test, it is normal and can be initialized. versionsprism0.17.3 |
Replies: 4 comments 1 reply
|
@small18 Can you provide more detail? Like: what code were you using to produce this problem? |
|
hi My nvgt project requires prism. Because I don't know much about c + +, I asked codex to write the prism plug-in integration. The following are the initialization functions that codex integrated for me: static bool prism_initialize() {
std::lock_guard<std::mutex> lock(g_mutex);
if (g_backend) return true;
g_last_error.clear();
wchar_t plugin_path[MAX_PATH] = {};
GetModuleFileNameW(g_plugin_module, plugin_path, MAX_PATH);
std::wstring prism_path(plugin_path);
size_t separator = prism_path.find_last_of(L"\\/");
prism_path = (separator == std::wstring::npos ? L"" : prism_path.substr(0, separator + 1)) + L"prism.dll";
g_library = LoadLibraryW(prism_path.c_str());
if (!g_library) {
g_last_error = "Unable to load prism.dll (Windows error " + std::to_string(GetLastError()) + ")";
return false;
}
if (!load_symbol(p_config_init, "prism_config_init") || !load_symbol(p_init, "prism_init") ||
!load_symbol(p_shutdown, "prism_shutdown") || !load_symbol(p_create_best, "prism_registry_create_best") ||
!load_symbol(p_backend_free, "prism_backend_free") || !load_symbol(p_backend_initialize, "prism_backend_initialize") ||
!load_symbol(p_backend_speak, "prism_backend_speak") || !load_symbol(p_backend_braille, "prism_backend_braille") ||
!load_symbol(p_backend_stop, "prism_backend_stop") ||
!load_symbol(p_backend_name, "prism_backend_name") || !load_symbol(p_error_string, "prism_error_string")) {
unload_prism();
return false;
}
PrismConfig config = p_config_init();
g_context = p_init(&config);
if (!g_context) {
g_last_error = "Prism could not create a context";
unload_prism();
return false;
}
g_backend = p_create_best(g_context);
if (!g_backend) {
g_last_error = "No supported Prism speech backend was found";
unload_prism();
return false;
}
PrismError error = p_backend_initialize(g_backend);
if (error != 0) {
g_last_error = p_error_string(error);
unload_prism();
return false;
}
return true;
} |
|
@small18 Thanks, this is a pretty good reason why. I'll go through the code and point out the problems. wchar_t plugin_path[MAX_PATH] = {};
GetModuleFileNameW(g_plugin_module, plugin_path, MAX_PATH);Two problems here. First, do not assume windows APIs are wide-character. (AI models absolutely love doing this, but MS's own advice states that you should NOT do this, nor should you mix them.) Always always always use the macros (in this case, Second, the problem causing your issue is this part: PrismConfig config = p_config_init();
g_context = p_init(&config);
if (!g_context) {
g_last_error = "Prism could not create a context";
unload_prism();
return false;
}
g_backend = p_create_best(g_context);
if (!g_backend) {
g_last_error = "No supported Prism speech backend was found";
unload_prism();
return false;
}
PrismError error = p_backend_initialize(g_backend);
if (error != 0) {
g_last_error = p_error_string(error);
unload_prism();
return false;
}Going through this:
You need only change the error check from: To: And things should work. |
|
As a note, I have converted this into a discussion as it is not a bug report. |
@small18 Thanks, this is a pretty good reason why. I'll go through the code and point out the problems.
Two problems here. First, do not assume windows APIs are wide-character. (AI models absolutely love doing this, but MS's own advice states that you should NOT do this, nor should you mix them.) Always always always use the macros (in this case,
GetModuleFileName,LoadLibrary, etc.), which will resolve to the correct functions that you should call. Second,GetModuleFileNameA/GetModuleFileNameWreturn an error code, so check that! Literally all of your wide-character code which follows from t…