diff --git a/BdaSpecials/IT35/TVTestRemocon/CCOMProc-x3U4Remocon.cpp b/BdaSpecials/IT35/TVTestRemocon/CCOMProc-x3U4Remocon.cpp index 2dd6908..e4b57e0 100644 --- a/BdaSpecials/IT35/TVTestRemocon/CCOMProc-x3U4Remocon.cpp +++ b/BdaSpecials/IT35/TVTestRemocon/CCOMProc-x3U4Remocon.cpp @@ -39,7 +39,12 @@ CCOMProc::CCOMProc(void) CCOMProc::~CCOMProc(void) { - TerminateThread(); + if (hThread) { + ::SetEvent(hTerminateRequest); + ::WaitForSingleObject(hThread, 1000); + ::CloseHandle(hThread); + hThread = NULL; + } if (hThreadInitComp) { ::CloseHandle(hThreadInitComp); hThreadInitComp = NULL; diff --git a/BdaSpecials/IT35/WinSCard-x3U4/CCOMProc-x3U4.cpp b/BdaSpecials/IT35/WinSCard-x3U4/CCOMProc-x3U4.cpp index 99a2777..c46f51f 100644 --- a/BdaSpecials/IT35/WinSCard-x3U4/CCOMProc-x3U4.cpp +++ b/BdaSpecials/IT35/WinSCard-x3U4/CCOMProc-x3U4.cpp @@ -42,7 +42,12 @@ CCOMProc::CCOMProc(void) CCOMProc::~CCOMProc(void) { - TerminateThread(); + if (hThread) { + ::SetEvent(hTerminateRequest); + ::WaitForSingleObject(hThread, 1000); + ::CloseHandle(hThread); + hThread = NULL; + } if (hThreadInitComp) { ::CloseHandle(hThreadInitComp); hThreadInitComp = NULL; diff --git a/BdaSpecials/IT35/WinSCard-x3U4/WinSCard-x3U4.cpp b/BdaSpecials/IT35/WinSCard-x3U4/WinSCard-x3U4.cpp index 6c8b152..d102ea8 100644 --- a/BdaSpecials/IT35/WinSCard-x3U4/WinSCard-x3U4.cpp +++ b/BdaSpecials/IT35/WinSCard-x3U4/WinSCard-x3U4.cpp @@ -21,7 +21,7 @@ static const WCHAR LIST_READERS_W[] = L"Plex PX-x3U4 Card Reader 0\0"; static BYTE IFSD = 254; // IFD側の最大受信可能ブロックサイズ static BOOL l_bInitialized = FALSE; - +static DWORD l_dwEstablishedContext = 0; static HANDLE l_hStartedEvent = NULL; static HMODULE l_hModule = NULL; static HANDLE l_hSemaphore = NULL; @@ -327,7 +327,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv break; case DLL_PROCESS_DETACH: - COMProc.TerminateThread(); CloseAllHandle(); if (l_hStartedEvent) { try { @@ -408,6 +407,9 @@ LONG WINAPI SCardDisconnect_(SCARDHANDLE hCard, DWORD dwDisposition) LONG WINAPI SCardEstablishContext_(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext) { + l_dwEstablishedContext++; + OutputDebug(L"SCardEstablishContext: Count=%d.\n", l_dwEstablishedContext); + *phContext = DUMMY_SCARDCONTEXT; return SCARD_S_SUCCESS; @@ -469,6 +471,15 @@ LONG WINAPI SCardListReadersW_(SCARDCONTEXT hContext, LPCWSTR mszGroups, LPWSTR LONG WINAPI SCardReleaseContext_(SCARDCONTEXT hContext) { + if (l_dwEstablishedContext) + l_dwEstablishedContext--; + OutputDebug(L"SCardReleaseContext: Count=%d.\n", l_dwEstablishedContext); + + if (!l_dwEstablishedContext) { + COMProc.TerminateThread(); + CloseAllHandle(); + } + return SCARD_S_SUCCESS; } diff --git a/doc/History-IT35.txt b/doc/History-IT35.txt index 51d81fd..dd3224e 100644 --- a/doc/History-IT35.txt +++ b/doc/History-IT35.txt @@ -16,3 +16,6 @@ 縲2017-02-27縲 繝サTVTest繝励Λ繧ー繧、繝ウ縺32bit迚医ョTVTest縺ォ隱崎ュ倥&繧後↑縺九▲縺溷撫鬘後r菫ョ豁」 +縲2017-03-01縲 +繝サTVTest繧堤オゆコ縺励※繧ゅ励Ο繧サ繧ケ縺梧ョ九▲縺溘∪縺セ縺ォ縺ェ繧句撫鬘後r菫ョ豁」 +