Skip to content

Commit

Permalink
Version 1.1 day1 lol
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrapivin committed May 7, 2021
1 parent 4ac53e8 commit 6257fa0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
23 changes: 19 additions & 4 deletions libmulti/libmulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ static ATOM nikWindowClass{ 0 };
std::vector<std::pair<HWND, CMultiD2D*>> 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions libmulti/libmulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ extern std::vector<std::pair<HWND, CMultiD2D*>> 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);
Expand Down
Binary file added libmulti/libmulti.rc
Binary file not shown.
4 changes: 4 additions & 0 deletions libmulti/libmulti.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<ItemGroup>
<ClInclude Include="libmulti.h" />
<ClInclude Include="MultiD2D.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
Expand All @@ -172,6 +173,9 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libmulti.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
8 changes: 8 additions & 0 deletions libmulti/libmulti.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<ClInclude Include="MultiD2D.h">
<Filter>Заголовочные файлы</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Заголовочные файлы</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -60,4 +63,9 @@
<Filter>Файлы исходного кода</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libmulti.rc">
<Filter>Файлы ресурсов</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions libmulti/libmulti_wndclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "stdafx.h"
#include "libmulti.h"

BOOL unregister_window_class(ATOM c, HINSTANCE hi) {
return UnregisterClass(reinterpret_cast<LPCTSTR>(c), hi);
}

ATOM register_window_class(WNDPROC p) {
WNDCLASSEX wnd;
wnd.cbSize = sizeof(wnd);
Expand Down
14 changes: 14 additions & 0 deletions libmulti/resource.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6257fa0

Please sign in to comment.