diff --git a/libmulti/libmulti.cpp b/libmulti/libmulti.cpp index 562d604..80ce934 100644 --- a/libmulti/libmulti.cpp +++ b/libmulti/libmulti.cpp @@ -9,10 +9,10 @@ static ATOM nikWindowClass{ 0 }; std::vector> vecWindows{ }; DWORD LastError{ ERROR_SUCCESS }; static char* LastString{ nullptr }; -static CRITICAL_SECTION Mutex{ 0 }; +static CRITICAL_SECTION* Mutex{ nullptr }; -void EnterVector(void) { EnterCriticalSection(&Mutex); } -void LeaveVector(void) { LeaveCriticalSection(&Mutex); } +void EnterVector(void) { EnterCriticalSection(Mutex); } +void LeaveVector(void) { LeaveCriticalSection(Mutex); } bool _libmulti_exists(double index) { bool ret = true; @@ -382,7 +382,8 @@ LIBMULTI_VOID RegisterCallbacks(char* p1, char* p2, char* p3, char* p4) { LIBMULTI_DOUBLE libmulti_init(void) { printf(__FUNCTION__ ": hello!\n"); fflush(stdout); - InitializeCriticalSection(&Mutex); + Mutex = new CRITICAL_SECTION(); + InitializeCriticalSection(Mutex); InitMultiD2D(); EnterVector(); nikWindowClass = register_window_class(WindowProc); @@ -391,6 +392,20 @@ LIBMULTI_DOUBLE libmulti_init(void) { return nikWindowClass; } +LIBMULTI_DOUBLE libmulti_quit(void) { + if (Mutex == nullptr) return -1.0; + EnterVector(); + for (const auto& pair : vecWindows) { + DestroyWindow(pair.first); + } + BOOL ok = unregister_window_class(nikWindowClass, hModule); + LastError = GetLastError(); + LeaveVector(); + DeleteCriticalSection(Mutex); + Mutex = nullptr; + return ok; +} + LIBMULTI_STRING libmulti_last_error_message(void) { EnterVector(); DWORD myError = LastError; diff --git a/libmulti/libmulti.h b/libmulti/libmulti.h index d46bcdd..2895fb7 100644 --- a/libmulti/libmulti.h +++ b/libmulti/libmulti.h @@ -29,10 +29,12 @@ extern std::vector> vecWindows; bool _libmulti_exists(double index); DWORD WINAPI libmulti_window_thread(LPVOID lpThreadParameter); ATOM register_window_class(WNDPROC p); +BOOL unregister_window_class(ATOM c, HINSTANCE hi); LIBMULTI_VOID RegisterCallbacks(char* p1, char* p2, char* p3, char* p4); LIBMULTI_DOUBLE libmulti_init(void); +LIBMULTI_DOUBLE libmulti_quit(void); LIBMULTI_DOUBLE libmulti_present(void); LIBMULTI_DOUBLE libmulti_exists(double index); LIBMULTI_DOUBLE libmulti_last_error_code(void); diff --git a/libmulti/libmulti.rc b/libmulti/libmulti.rc new file mode 100644 index 0000000..0d571ad Binary files /dev/null and b/libmulti/libmulti.rc differ diff --git a/libmulti/libmulti.vcxproj b/libmulti/libmulti.vcxproj index 6318cb5..4567944 100644 --- a/libmulti/libmulti.vcxproj +++ b/libmulti/libmulti.vcxproj @@ -153,6 +153,7 @@ + @@ -172,6 +173,9 @@ Create + + + diff --git a/libmulti/libmulti.vcxproj.filters b/libmulti/libmulti.vcxproj.filters index f33ce07..1f85fba 100644 --- a/libmulti/libmulti.vcxproj.filters +++ b/libmulti/libmulti.vcxproj.filters @@ -30,6 +30,9 @@ Заголовочные файлы + + Заголовочные файлы + @@ -60,4 +63,9 @@ Файлы исходного кода + + + Файлы ресурсов + + \ No newline at end of file diff --git a/libmulti/libmulti_wndclass.cpp b/libmulti/libmulti_wndclass.cpp index cc310c7..1e6237b 100644 --- a/libmulti/libmulti_wndclass.cpp +++ b/libmulti/libmulti_wndclass.cpp @@ -3,6 +3,10 @@ #include "stdafx.h" #include "libmulti.h" +BOOL unregister_window_class(ATOM c, HINSTANCE hi) { + return UnregisterClass(reinterpret_cast(c), hi); +} + ATOM register_window_class(WNDPROC p) { WNDCLASSEX wnd; wnd.cbSize = sizeof(wnd); diff --git a/libmulti/resource.h b/libmulti/resource.h new file mode 100644 index 0000000..d49be1b --- /dev/null +++ b/libmulti/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by libmulti.rc + +// +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif