diff --git a/cpp/common.hpp b/cpp/common.hpp index 525ae8ff..dc0ac967 100644 --- a/cpp/common.hpp +++ b/cpp/common.hpp @@ -1,20 +1,4 @@ -struct AutoHandle -{ - HANDLE _handle; - AutoHandle(HANDLE handle) : _handle(handle) {}; - ~AutoHandle() - { - CloseHandle(_handle); - } - operator HANDLE() - { - return _handle; - } - operator bool() - { - return _handle == INVALID_HANDLE_VALUE; - } -}; + inline SECURITY_ATTRIBUTES allAccess = std::invoke([] // allows non-admin processes to access kernel objects made by admin processes { static SECURITY_DESCRIPTOR sd = {}; diff --git a/cpp/exec/PyStand.cpp b/cpp/exec/PyStand.cpp index 3ff8c2f1..ab0e4597 100644 --- a/cpp/exec/PyStand.cpp +++ b/cpp/exec/PyStand.cpp @@ -323,11 +323,11 @@ int main() { { // 当更新进行时,禁止启动 - AutoHandle hMutex = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE"); + CHandle hMutex{CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE")}; if (GetLastError() == ERROR_ALREADY_EXISTS) return 0; } - auto __handle = AutoHandle(CreateMutexA(&allAccess, FALSE, "LUNA_UPDATER_BLOCK")); + CHandle __handle{CreateMutexA(&allAccess, FALSE, "LUNA_UPDATER_BLOCK")}; PyStand ps(L"files\\runtime"); if (ps.DetectScript() != 0) { diff --git a/cpp/implsapi.cpp b/cpp/implsapi.cpp index fe1112fa..3bfd1869 100644 --- a/cpp/implsapi.cpp +++ b/cpp/implsapi.cpp @@ -55,10 +55,10 @@ std::optional> _Speak(std::wstring &Content, const wchar_t *to ULONG bytesRead; // this will tell the number of bytes that have been read std::vector datas; - datas.resize(sSize + 0x3ea); + datas.resize(sSize + 46); auto pBuffer = datas.data(); // buffer to read the data // memcpy(pBuffer,&wavHeader,sizeof(WAV_HEADER)); - int fsize = sSize + 0x3ea; + int fsize = sSize + 46; int ptr = 0; memcpy(pBuffer, "RIFF", 4); ptr += 4; diff --git a/cpp/pch.h b/cpp/pch.h index 29aaa737..e4df0858 100644 --- a/cpp/pch.h +++ b/cpp/pch.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/cpp/shareddllproxy/Atlas.cpp b/cpp/shareddllproxy/Atlas.cpp index 36a65652..39738847 100644 --- a/cpp/shareddllproxy/Atlas.cpp +++ b/cpp/shareddllproxy/Atlas.cpp @@ -489,51 +489,10 @@ char *TranslateFull(char *otext, int freeText, int NeedAbort(int line, int lines return out; } -static wchar_t *logFile = 0; -void SetLogFile(wchar_t *file) -{ - logFile = file; -} - -wchar_t *TranslateFullLog(wchar_t *otext) -{ - if (logFile && logFile[0]) - { - HANDLE hMutex = CreateMutex(0, 0, L"TRAG Logging Super Mutext +10 from Outer Space"); - DWORD res; - if (hMutex) - res = WaitForSingleObject(hMutex, 2000); - HANDLE hFile = CreateFile(logFile, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); - if (hFile != INVALID_HANDLE_VALUE) - { - DWORD junk; - if (GetLastError() == ERROR_ALREADY_EXISTS) - SetFilePointer(hFile, 0, 0, FILE_END); - else - { - wchar_t bom = 0xFEFF; - WriteFile(hFile, &bom, sizeof(wchar_t), &junk, 0); - } - WriteFile(hFile, otext, sizeof(wchar_t) * wcslen(otext), &junk, 0); - WriteFile(hFile, L"\r\n", sizeof(wchar_t) * 2, &junk, 0); - CloseHandle(hFile); - } - if (hMutex) - { - // Prolly not needed. - if (WAIT_OBJECT_0 == res) - ReleaseMutex(hMutex); - CloseHandle(hMutex); - } - } - return TranslateFull(otext); -} - struct AtlasConfig atlcfg; void writestring(const wchar_t *text, HANDLE hPipe); wchar_t *readstring(HANDLE hPipe); -HANDLE mutex = NULL; int atlaswmain(int argc, wchar_t *argv[]) { @@ -548,33 +507,6 @@ int atlaswmain(int argc, wchar_t *argv[]) if (!src) break; - if (!mutex) - { - mutex = CreateMutex(NULL, FALSE, NULL); - if (!mutex) - { - return false; - } - } - bool waitingForMutex = true; - while (waitingForMutex) - { - switch (WaitForSingleObject(mutex, INFINITE)) - { - case WAIT_OBJECT_0: - { - waitingForMutex = false; - break; - } - case WAIT_ABANDONED: - { - return false; - } - default: - { - } - } - } if (!AtlasIsLoaded()) { // atlcfg.flags = ~BREAK_ON_SINGLE_LINE_BREAKS; @@ -583,7 +515,6 @@ int atlaswmain(int argc, wchar_t *argv[]) InitAtlas(atlcfg, ATLAS_JAP_TO_ENG); if (!AtlasIsLoaded()) { - ReleaseMutex(mutex); writestring(0, hPipe); return false; } @@ -592,7 +523,6 @@ int atlaswmain(int argc, wchar_t *argv[]) writestring(text, hPipe); free(src); free(text); - ReleaseMutex(mutex); } return 0; diff --git a/cpp/shareddllproxy/Atlas.h b/cpp/shareddllproxy/Atlas.h index 57c7db26..960d4b3a 100644 --- a/cpp/shareddllproxy/Atlas.h +++ b/cpp/shareddllproxy/Atlas.h @@ -39,9 +39,6 @@ char *TranslateFull(char *otext, int freeText = 0, int NeedAbort(int line, int l int AtlasIsLoaded(); -// dirty hack -void SetLogFile(wchar_t *file); -wchar_t *TranslateFullLog(wchar_t *otext); /* wchar_t path[MAX_PATH]; GetCurrentDirectory(MAX_PATH, path); diff --git a/cpp/shareddllproxy/aspatch.cpp b/cpp/shareddllproxy/aspatch.cpp index 024a6f4f..a2fdcabb 100644 --- a/cpp/shareddllproxy/aspatch.cpp +++ b/cpp/shareddllproxy/aspatch.cpp @@ -39,7 +39,7 @@ std::wstring stolower(const std::wstring &s1) std::vector EnumerateProcesses(const std::wstring &exe) { - AutoHandle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + CHandle hSnapshot{CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)}; if (hSnapshot == INVALID_HANDLE_VALUE) { return {}; diff --git a/cpp/shareddllproxy/update.cpp b/cpp/shareddllproxy/update.cpp index eabec2f9..e6bc9b3d 100644 --- a/cpp/shareddllproxy/update.cpp +++ b/cpp/shareddllproxy/update.cpp @@ -5,13 +5,13 @@ int updatewmain(int argc, wchar_t *argv[]) if (argc <= 1) return 0; SetProcessDPIAware(); - AutoHandle hMutex = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE"); + CHandle hMutex{CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE")}; if (GetLastError() == ERROR_ALREADY_EXISTS) return 0; while (true) { - AutoHandle semaphore = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_BLOCK"); + CHandle semaphore{CreateMutex(NULL, FALSE, L"LUNA_UPDATER_BLOCK")}; if (GetLastError() != ERROR_ALREADY_EXISTS) break; Sleep(1000); diff --git a/cpp/shareddllproxy/voiceroid2/api_adapter.cc b/cpp/shareddllproxy/voiceroid2/api_adapter.cc index 70f611a2..9627405b 100644 --- a/cpp/shareddllproxy/voiceroid2/api_adapter.cc +++ b/cpp/shareddllproxy/voiceroid2/api_adapter.cc @@ -26,12 +26,10 @@ namespace ebyroid ApiAdapter *ApiAdapter::Create(const char *dllpath) { - printf("dllpath %s\n", dllpath); HINSTANCE handle = LoadLibraryA(dllpath); if (handle == nullptr) { char m[128]; - printf("load error\n"); std::snprintf(m, 128, "LoadLibrary failed with code %d (Check out the voiceroid path setting)", @@ -52,7 +50,6 @@ namespace ebyroid adapter->text_to_speech_ = LoadProc(handle, "_AITalkAPI_TextToSpeech@12"); adapter->close_speech_ = LoadProc(handle, "_AITalkAPI_CloseSpeech@8"); adapter->get_data_ = LoadProc(handle, "_AITalkAPI_GetData@16"); - printf("load dll ok\n"); return adapter; } diff --git a/cpp/shareddllproxy/voiceroid2/ebyroid.cc b/cpp/shareddllproxy/voiceroid2/ebyroid.cc index cc774236..e149ace3 100644 --- a/cpp/shareddllproxy/voiceroid2/ebyroid.cc +++ b/cpp/shareddllproxy/voiceroid2/ebyroid.cc @@ -34,28 +34,17 @@ namespace ebyroid return ebyroid; } - int Ebyroid::Hiragana(const unsigned char *inbytes, unsigned char **outbytes, size_t *outsize) + int Ebyroid::Hiragana(const char *inbytes, std::vector &output) { - Response *const response = new Response(api_adapter_); - printf("1\n"); + Response response{api_adapter_}; TJobParam param; param.mode_in_out = IOMODE_PLAIN_TO_AIKANA; - param.user_data = response; + param.user_data = &response; - char eventname[32]; - std::sprintf(eventname, "TTKLOCK:%p", response); - printf("12\n"); - HANDLE event = CreateEventA(NULL, TRUE, FALSE, eventname); - printf("3\n"); int32_t job_id; - ResultCode result = api_adapter_->TextToKana(&job_id, ¶m, (const char *)inbytes); - printf("4\n"); + ResultCode result = api_adapter_->TextToKana(&job_id, ¶m, inbytes); if (result != ERR_SUCCESS) { - delete response; - printf("%d\n", result); - ResetEvent(event); - CloseHandle(event); static const char *format = "TextToKana failed with the result code %d\n" "Given inbytes: %s"; @@ -63,53 +52,33 @@ namespace ebyroid std::snprintf(m, 0xFFFF, format, result, inbytes); throw std::runtime_error(m); } - printf("6\n"); - WaitForSingleObject(event, INFINITE); - ResetEvent(event); - CloseHandle(event); - printf("8\n"); + WaitForSingleObject(response.event, INFINITE); // finalize result = api_adapter_->CloseKana(job_id); if (result != ERR_SUCCESS) { - delete response; throw std::runtime_error("wtf"); } // write to output memory - vector buffer = response->End(); - *outsize = buffer.size(); - *outbytes = (unsigned char *)malloc(buffer.size() + 1); - std::copy(buffer.begin(), buffer.end(), *outbytes); - *(*outbytes + buffer.size()) = '\0'; - - delete response; + output = response.End(); return 0; } - int Ebyroid::Speech(const unsigned char *inbytes, - int16_t **outbytes, - size_t *outsize, - uint32_t mode) + int Ebyroid::Speech(const char *inbytes, std::vector &output, uint32_t mode) { - Response *const response = new Response(api_adapter_); + Response response{api_adapter_}; TJobParam param; param.mode_in_out = mode == 0u ? IOMODE_AIKANA_TO_WAVE : (JobInOut)mode; - param.user_data = response; + param.user_data = &response; - char eventname[32]; - sprintf(eventname, "TTSLOCK:%p", response); - HANDLE event = CreateEventA(NULL, TRUE, FALSE, eventname); int32_t job_id; - ResultCode result = api_adapter_->TextToSpeech(&job_id, ¶m, (const char *)inbytes); + ResultCode result = api_adapter_->TextToSpeech(&job_id, ¶m, inbytes); if (result != ERR_SUCCESS) { - delete response; - ResetEvent(event); - CloseHandle(event); static const char *format = "TextToSpeech failed with the result code %d\n" "Given inbytes: %s"; char m[0xFFFF]; @@ -117,49 +86,21 @@ namespace ebyroid throw std::runtime_error(m); } - WaitForSingleObject(event, INFINITE); - ResetEvent(event); - CloseHandle(event); + WaitForSingleObject(response.event, INFINITE); // finalize result = api_adapter_->CloseSpeech(job_id); if (result != ERR_SUCCESS) { - delete response; throw std::runtime_error("wtf"); } // write to output memory - vector buffer = response->End16(); - *outsize = buffer.size() * 2; // sizeof(int16_t) == 2 - *outbytes = (int16_t *)malloc(buffer.size() * 2 + 1); - std::copy(buffer.begin(), buffer.end(), *outbytes); - *((char *)*outbytes + (buffer.size() * 2)) = '\0'; + output = response.End(); - delete response; return 0; } - void Response::Write(char *bytes, uint32_t size) - { - buffer_.insert(std::end(buffer_), bytes, bytes + size); - } - - void Response::Write16(int16_t *shorts, uint32_t size) - { - buffer_16_.insert(std::end(buffer_16_), shorts, shorts + size); - } - - vector Response::End() - { - return std::move(buffer_); - } - - vector Response::End16() - { - return std::move(buffer_16_); - } - namespace { @@ -167,8 +108,7 @@ namespace ebyroid { SettingsBuilder builder(base_dir, voice); Settings settings = builder.Build(); - - ApiAdapter *adapter = ApiAdapter::Create(dllpath.c_str()); + std::unique_ptr adapter{ApiAdapter::Create(dllpath.c_str())}; TConfig config; config.hz_voice_db = settings.frequency; @@ -184,39 +124,17 @@ namespace ebyroid config.code_auth_seed = "PROJECT-VOICeVIO-SFE"; result = adapter->Init(&config); } - printf("init %d\n", result); if (result != ERR_SUCCESS) { - delete adapter; string message = "API initialization failed with code "; message += std::to_string(result); throw std::runtime_error(message); } - /*pairxx = WithDirecory(settings.base_dir, [adapter, settings]() { - ResultCode result = adapter->LangLoad(settings.language_dir); - printf("laod lang %d\n", result); - if (result != ERR_SUCCESS) { - char m[64]; - std::snprintf(m, 64, "API LangLoad failed (could not load language) with code %d", result); - return pair(true, string(m)); - } - return pair(false, string()); - });*/ - bool x = SetCurrentDirectoryA(settings.base_dir); SetDllDirectoryA(settings.base_dir); - printf("%d\n", x); - wchar_t buffer[1000] = {0}; - DWORD sz = 1000; - GetCurrentDirectoryW(sz, buffer); - wprintf(L"%s\n", buffer); result = adapter->LangLoad(settings.language_dir); - printf("%s %s \n", settings.base_dir, settings.language_dir); - printf("loadvoice %d\n", result); result = adapter->VoiceLoad(settings.voice_name); - printf("loadvoice %s %d\n", settings.voice_name, result); if (result != ERR_SUCCESS) { - delete adapter; string message = "API Load Voice failed (Could not load voice data) with code "; message += std::to_string(result); throw std::runtime_error(message); @@ -225,96 +143,73 @@ namespace ebyroid result = adapter->GetParam((void *)0, ¶m_size); if (result != ERR_INSUFFICIENT) { // NOTE: Code -20 is expected here - delete adapter; string message = "API Get Param failed (Could not acquire the size) with code "; message += std::to_string(result); throw std::runtime_error(message); } - - printf("param->size %d\n", param_size); - if (param_size == 500) + if (param_size == sizeof(TTtsParam)) { // voiceroid2 - char *param_buffer = new char[param_size]; - TTtsParam *param = (TTtsParam *)param_buffer; + TTtsParam param; // TTtsParam* param = (TTtsParam*) param_buffer; - param->size = param_size; - result = adapter->GetParam(param, ¶m_size); - printf("%s %d\n", "GetParam", result); + param.size = param_size; + result = adapter->GetParam(¶m, ¶m_size); if (result != ERR_SUCCESS) { - delete[] param_buffer; - delete adapter; string message = "API Get Param failed with code "; message += std::to_string(result); throw std::runtime_error(message); } - param->extend_format = BOTH; - param->proc_text_buf = HiraganaCallback; - param->proc_raw_buf = SpeechCallback; - param->proc_event_tts = nullptr; - param->len_raw_buf_bytes = kConfigRawbufSize; + param.extend_format = BOTH; + param.proc_text_buf = HiraganaCallback; + param.proc_raw_buf = SpeechCallback; + param.proc_event_tts = nullptr; + param.len_raw_buf_bytes = kConfigRawbufSize; - param->volume = volume; - printf("1\n"); - param->speaker[0].volume = volume; - /*param->speaker[0].pitch = 1.111; - param->speaker[0].pause_middle = 80; - param->speaker[0].pause_sentence = 200; - param->speaker[0].pause_long = 100; - param->speaker[0].range = 0.893;*/ - param->speaker[0].speed = speed; - //printf("2 %d %d\n", volume, speed); - result = adapter->SetParam(param); - printf("3 %d\n", result); + param.volume = volume; + param.speaker[0].volume = volume; + /*param.speaker[0].pitch = 1.111; + param.speaker[0].pause_middle = 80; + param.speaker[0].pause_sentence = 200; + param.speaker[0].pause_long = 100; + param.speaker[0].range = 0.893;*/ + param.speaker[0].speed = speed; + result = adapter->SetParam(¶m); if (result != ERR_SUCCESS) { - delete[] param_buffer; - delete adapter; string message = "API Set Param failed with code "; message += std::to_string(result); throw std::runtime_error(message); } - printf("3\n"); - delete[] param_buffer; } - else if (param_size == 416) + else if (param_size == sizeof(AITalk_TTtsParam)) { // voiceroid+ - char *param_buffer = new char[param_size]; - AITalk_TTtsParam *param = (AITalk_TTtsParam *)param_buffer; + AITalk_TTtsParam param; // TTtsParam* param = (TTtsParam*) param_buffer; - param->size = param_size; - result = adapter->GetParam(param, ¶m_size); + param.size = param_size; + result = adapter->GetParam(¶m, ¶m_size); if (result != ERR_SUCCESS) { - delete[] param_buffer; - delete adapter; string message = "API Get Param failed with code "; message += std::to_string(result); throw std::runtime_error(message); } - printf("numSpeakers %d\n", param->numSpeakers); - param->proc_text_buf = HiraganaCallback; - param->proc_raw_buf = SpeechCallback; - param->proc_event_tts = nullptr; - param->lenRawBufBytes = kConfigRawbufSize; + param.proc_text_buf = HiraganaCallback; + param.proc_raw_buf = SpeechCallback; + param.proc_event_tts = nullptr; + param.lenRawBufBytes = kConfigRawbufSize; - param->volume = volume; - result = adapter->SetParam(param); - printf("SetParam ok %d\n", result); + param.volume = volume; + result = adapter->SetParam(¶m); if (result != ERR_SUCCESS) { - delete[] param_buffer; - delete adapter; string message = "API Set Param failed with code "; message += std::to_string(result); - printf("%s\n", message.c_str()); throw std::runtime_error(message); } - delete[] param_buffer; } - - printf("%s \n", "setparam all ok"); - return adapter; + auto _ = adapter.get(); + adapter.release(); + return _; } inline pair WithDirecory(const char *dir, function(void)> yield) @@ -360,7 +255,7 @@ namespace ebyroid } int __stdcall HiraganaCallback(EventReasonCode reason_code, int32_t job_id, IntPtr user_data) { - Response *const response = (Response *)user_data; + auto response = (Response *)user_data; ApiAdapter *api_adapter = response->api_adapter(); if (reason_code != TEXTBUF_FULL && reason_code != TEXTBUF_FLUSH && reason_code != TEXTBUF_CLOSE) @@ -370,7 +265,7 @@ namespace ebyroid } static constexpr int kBufferSize = 0x1000; - char *buffer = new char[kBufferSize]; + char buffer[kBufferSize]; while (true) { uint32_t size, pos; @@ -386,14 +281,10 @@ namespace ebyroid break; } } - delete[] buffer; if (reason_code == TEXTBUF_CLOSE) { - char eventname[32]; - sprintf(eventname, "TTKLOCK:%p", response); - HANDLE event = OpenEventA(EVENT_ALL_ACCESS, FALSE, eventname); - SetEvent(event); + response->event.Set(); } return 0; } @@ -403,7 +294,7 @@ namespace ebyroid uint64_t tick, IntPtr user_data) { - Response *const response = (Response *)user_data; + auto response = (Response *)user_data; ApiAdapter *api_adapter = response->api_adapter(); if (reason_code != RAWBUF_FULL && reason_code != RAWBUF_FLUSH && reason_code != RAWBUF_CLOSE) @@ -413,7 +304,7 @@ namespace ebyroid } static constexpr int kBufferSize = 0xFFFF; - int16_t *buffer = new int16_t[kBufferSize]; + int16_t buffer[kBufferSize]; while (true) { uint32_t size, pos; @@ -422,20 +313,16 @@ namespace ebyroid { break; } - response->Write16(buffer, size); + response->Write(buffer, size); if (kBufferSize > size) { break; } } - delete[] buffer; if (reason_code == RAWBUF_CLOSE) { - char eventname[32]; - sprintf(eventname, "TTSLOCK:%p", response); - HANDLE event = OpenEventA(EVENT_ALL_ACCESS, FALSE, eventname); - SetEvent(event); + response->event.Set(); } return 0; } diff --git a/cpp/shareddllproxy/voiceroid2/ebyroid.h b/cpp/shareddllproxy/voiceroid2/ebyroid.h index 14a5468c..330f5812 100644 --- a/cpp/shareddllproxy/voiceroid2/ebyroid.h +++ b/cpp/shareddllproxy/voiceroid2/ebyroid.h @@ -1,7 +1,6 @@ #ifndef EBYROID_H #define EBYROID_H - namespace ebyroid { @@ -24,8 +23,8 @@ namespace ebyroid ~Ebyroid(); static Ebyroid *Create(const std::string &base_dir, const std::string &dllpath, const std::string &voice, float volume, float speed); - int Hiragana(const unsigned char *inbytes, unsigned char **outbytes, size_t *outsize); - int Speech(const unsigned char *inbytes, int16_t **outbytes, size_t *outsize, uint32_t mode = 0u); + int Hiragana(const char *inbytes, std::vector &); + int Speech(const char *inbytes, std::vector &, uint32_t mode = 0u); int Convert(const ConvertParams ¶ms, const unsigned char *inbytes, int16_t **outbytes, @@ -36,20 +35,27 @@ namespace ebyroid ApiAdapter *api_adapter_; }; + template class Response { public: - Response(ApiAdapter *adapter) : api_adapter_(adapter) {} - void Write(char *bytes, uint32_t size); - void Write16(int16_t *shorts, uint32_t size); - std::vector End(); - std::vector End16(); + Response(ApiAdapter *adapter) : api_adapter_(adapter) + { + event.Create(NULL, FALSE, FALSE, NULL); + } + void Write(T *bytes, size_t size) + { + buffer_.insert(std::end(buffer_), bytes, bytes + size); + } + std::vector End() + { + return std::move(buffer_); + } ApiAdapter *api_adapter() { return api_adapter_; }; - + CEvent event; private: ApiAdapter *api_adapter_; - std::vector buffer_; - std::vector buffer_16_; + std::vector buffer_; }; } // namespace ebyroid diff --git a/cpp/shareddllproxy/voiceroid2/voice2.cpp b/cpp/shareddllproxy/voiceroid2/voice2.cpp index 23afc89b..7261e193 100644 --- a/cpp/shareddllproxy/voiceroid2/voice2.cpp +++ b/cpp/shareddllproxy/voiceroid2/voice2.cpp @@ -28,14 +28,11 @@ int voiceroid2wmain(int argc, wchar_t *wargv[]) SetEvent(CreateEventA(&allAccess, FALSE, FALSE, argv[4])); ConnectNamedPipe(hPipe, NULL); int freq1; - unsigned char input_j[4096] = {0}; + char input_j[4096] = {0}; DWORD _; while (true) { ZeroMemory(input_j, sizeof(input_j)); - unsigned char *out; - size_t output_size; - int16_t *out2; if (!ReadFile(hPipe, input_j, 4096, &_, NULL)) break; @@ -51,8 +48,8 @@ int voiceroid2wmain(int argc, wchar_t *wargv[]) { delete ebyroid; } - ebyroid = Ebyroid::Create((const char *)argv[1], //"C:\\dataH\\Yukari2", - (const char *)argv[2], + ebyroid = Ebyroid::Create(argv[1], //"C:\\dataH\\Yukari2", + argv[2], voice.c_str(), 2, rate); // 1); //0.1-2,0.5-4 @@ -65,10 +62,12 @@ int voiceroid2wmain(int argc, wchar_t *wargv[]) freq1 = 44100; else freq1 = 22050; - // int result = ebyroid->Hiragana((const unsigned char*)UnicodeToShift_jis(input), &out, &output_size); - int result = ebyroid->Hiragana((const unsigned char *)input_j, &out, &output_size); - - result = ebyroid->Speech(out, &out2, &output_size); + std::vector output; + int result = ebyroid->Hiragana(input_j, output); + output.push_back(0); + std::vector binary; + result = ebyroid->Speech(output.data(), binary); + size_t output_size = binary.size() * 2; int fsize = output_size + 44; if (fsize > 1024 * 1024 * 10) { @@ -98,12 +97,9 @@ int voiceroid2wmain(int argc, wchar_t *wargv[]) ptr += 4; memcpy(mapview + ptr, &output_size, 4); ptr += 4; - memcpy(mapview + ptr, out2, output_size); + memcpy(mapview + ptr, binary.data(), output_size); } WriteFile(hPipe, &fsize, 4, &_, NULL); - - free(out); - free(out2); } return 0; } diff --git a/cpp/winsharedutils/hwnd.cpp b/cpp/winsharedutils/hwnd.cpp index 477626aa..0c81b3f1 100644 --- a/cpp/winsharedutils/hwnd.cpp +++ b/cpp/winsharedutils/hwnd.cpp @@ -26,18 +26,20 @@ DECLARE_API void showintab(HWND hwnd, bool show, bool tool) DECLARE_API bool pid_running(DWORD pid) { - DWORD code; + CHandle hprocess{OpenProcess( #ifndef WINXP - GetExitCodeProcess(AutoHandle(OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid)), &code); + PROCESS_QUERY_LIMITED_INFORMATION, #else - GetExitCodeProcess(AutoHandle(OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)), &code); + PROCESS_QUERY_INFORMATION, #endif + FALSE, pid)}; + if (!hprocess) + return false; + DWORD code; + GetExitCodeProcess(hprocess, &code); // 句柄必須具有 PROCESS_QUERY_INFORMATION 或 PROCESS_QUERY_LIMITED_INFORMATION 訪問許可權。 如需詳細資訊,請參閱 處理安全性和訪問許可權。 // Windows Server 2003 和 Windows XP: 句柄必須具有 PROCESS_QUERY_INFORMATION 訪問許可權。 return code == STILL_ACTIVE; - // auto process = AutoHandle(OpenProcess(SYNCHRONIZE, FALSE, pid)); - // DWORD ret = WaitForSingleObject(process, 0); - // return ret == WAIT_TIMEOUT; } struct __EnumWindowsProc @@ -79,11 +81,13 @@ DECLARE_API bool Is64bit(DWORD pid) { if (!Is64BitOS()) return false; + CHandle hprocess{OpenProcess( #ifndef WINXP - auto hprocess = AutoHandle(OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid)); + PROCESS_QUERY_LIMITED_INFORMATION, #else - auto hprocess = AutoHandle(OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)); + PROCESS_QUERY_INFORMATION, #endif + FALSE, pid)}; // 進程的控制碼。 控制碼必須具有PROCESS_QUERY_INFORMATION或PROCESS_QUERY_LIMITED_INFORMATION存取權限。 如需詳細資訊,請參閱 處理安全性和存取權限。 // Windows Server 2003 和 Windows XP: 控制碼必須具有PROCESS_QUERY_INFORMATION存取權限。 BOOL f64bitProc = false; @@ -94,7 +98,7 @@ DECLARE_API bool Is64bit(DWORD pid) DECLARE_API void getprocesses(void (*cb)(DWORD, const wchar_t *)) { std::unordered_map> exe_pid; - AutoHandle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + CHandle hSnapshot{CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)}; if (hSnapshot == INVALID_HANDLE_VALUE) return;