From 9c7210e15fa61ad50629dea2a6086d9963b208a5 Mon Sep 17 00:00:00 2001 From: JongKook Kim Date: Wed, 14 Jul 2021 15:25:58 +0900 Subject: [PATCH] fix utf8 converting --- Resource.rc | 8 +++---- example/exampleConsole/exampleConsole.c | 4 ++-- include/kw_.h | 30 ++++++++++++------------- src/kw_.cpp | 2 +- src/kwapi.h | 4 +++- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Resource.rc b/Resource.rc index 6651a0b..9f5789e 100644 --- a/Resource.rc +++ b/Resource.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,5,0 - PRODUCTVERSION 0,0,5,0 + FILEVERSION 0,0,6,0 + PRODUCTVERSION 0,0,6,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "TODO: <ȸ ̸>" VALUE "FileDescription", "TODO: < >" - VALUE "FileVersion", "0.0.5.0" + VALUE "FileVersion", "0.0.6.0" VALUE "InternalName", "kw_.dll" VALUE "LegalCopyright", "Copyright (C) 2021 Kim, Jong-Kook" VALUE "OriginalFilename", "kw_.dll" VALUE "ProductName", "TODO: <ǰ ̸>" - VALUE "ProductVersion", "0.0.5.0" + VALUE "ProductVersion", "0.0.6.0" END END BLOCK "VarFileInfo" diff --git a/example/exampleConsole/exampleConsole.c b/example/exampleConsole/exampleConsole.c index 6b57eb7..2914ffa 100644 --- a/example/exampleConsole/exampleConsole.c +++ b/example/exampleConsole/exampleConsole.c @@ -3,7 +3,7 @@ #include "kw_.h" #pragma comment(lib, "kw_.lib") -void CALLBACK OnEventConnect(long errCode) { +void OnEventConnect(long errCode) { if (errCode == 0) { puts("로그인 성공"); @@ -14,7 +14,7 @@ void CALLBACK OnEventConnect(long errCode) { } else { puts("로그인 실패"); - exit(0); + kw_Disconnect(); } } diff --git a/include/kw_.h b/include/kw_.h index 70fb028..38ee8d3 100644 --- a/include/kw_.h +++ b/include/kw_.h @@ -215,42 +215,42 @@ KW_API void kw_SetRealRemoveA(PCSTR strScrNo, PCSTR strDelCode); KW_API long kw_GetMarketTypeW(PCWSTR sTrCode); KW_API long kw_GetMarketTypeA(PCSTR sTrCode); -typedef void (CALLBACK* kw_OnEventConnect)(long nErrCode); +typedef void (*kw_OnEventConnect)(long nErrCode); -typedef void (CALLBACK* kw_OnReceiveTrDataW)(PCWSTR sScrNo, PCWSTR sRQName, +typedef void (*kw_OnReceiveTrDataW)(PCWSTR sScrNo, PCWSTR sRQName, PCWSTR sTrCode, PCWSTR sRecordName, PCWSTR sPrevNext, long nDataLength, PCWSTR sErrorCode, PCWSTR sMessage, PCWSTR sSplmMsg); -typedef void (CALLBACK* kw_OnReceiveTrDataA)(PCSTR sScrNo, PCSTR sRQName, +typedef void (*kw_OnReceiveTrDataA)(PCSTR sScrNo, PCSTR sRQName, PCSTR sTrCode, PCSTR sRecordName, PCSTR sPrevNext, long nDataLength, PCSTR sErrorCode, PCSTR sMessage, PCSTR sSplmMsg); -typedef void (CALLBACK* kw_OnReceiveRealDataW)(PCWSTR sRealKey, +typedef void (*kw_OnReceiveRealDataW)(PCWSTR sRealKey, PCWSTR sRealType, PCWSTR sRealData); -typedef void (CALLBACK* kw_OnReceiveRealDataA)(PCSTR sRealKey, +typedef void (*kw_OnReceiveRealDataA)(PCSTR sRealKey, PCSTR sRealType, PCSTR sRealData); -typedef void (CALLBACK* kw_OnReceiveMsgW)(PCWSTR sScrNo, PCWSTR sRQName, +typedef void (*kw_OnReceiveMsgW)(PCWSTR sScrNo, PCWSTR sRQName, PCWSTR sTrCode, PCWSTR sMsg); -typedef void (CALLBACK* kw_OnReceiveMsgA)(PCSTR sScrNo, PCSTR sRQName, +typedef void (*kw_OnReceiveMsgA)(PCSTR sScrNo, PCSTR sRQName, PCSTR sTrCode, PCSTR sMsg); -typedef void (CALLBACK* kw_OnReceiveChejanDataW)(PCWSTR sGubun, long nItemCnt, +typedef void (*kw_OnReceiveChejanDataW)(PCWSTR sGubun, long nItemCnt, PCWSTR sFIdList); -typedef void (CALLBACK* kw_OnReceiveChejanDataA)(PCSTR sGubun, long nItemCnt, +typedef void (*kw_OnReceiveChejanDataA)(PCSTR sGubun, long nItemCnt, PCSTR sFIdList); -typedef void (CALLBACK* kw_OnReceiveRealConditionW)(PCWSTR sTrCode, +typedef void (*kw_OnReceiveRealConditionW)(PCWSTR sTrCode, PCWSTR strType, PCWSTR strConditionName, PCWSTR strConditionIndex); -typedef void (CALLBACK* kw_OnReceiveRealConditionA)(PCSTR sTrCode, +typedef void (*kw_OnReceiveRealConditionA)(PCSTR sTrCode, PCSTR strType, PCSTR strConditionName, PCSTR strConditionIndex); -typedef void (CALLBACK* kw_OnReceiveTrConditionW)(PCWSTR sScrNo, +typedef void (*kw_OnReceiveTrConditionW)(PCWSTR sScrNo, PCWSTR strCodeList, PCWSTR strConditionName, int nIndex, int nNext); -typedef void (CALLBACK* kw_OnReceiveTrConditionA)(PCSTR sScrNo, +typedef void (*kw_OnReceiveTrConditionA)(PCSTR sScrNo, PCSTR strCodeList, PCSTR strConditionName, int nIndex, int nNext); -typedef void (CALLBACK* kw_OnReceiveConditionVerW)(long lRet, PCWSTR sMsg); -typedef void (CALLBACK* kw_OnReceiveConditionVerA)(long lRet, PCSTR sMsg); +typedef void (*kw_OnReceiveConditionVerW)(long lRet, PCWSTR sMsg); +typedef void (*kw_OnReceiveConditionVerA)(long lRet, PCSTR sMsg); KW_API void kw_SetOnEventConnect(kw_OnEventConnect handler); diff --git a/src/kw_.cpp b/src/kw_.cpp index 7dfa3bb..5cde3d9 100644 --- a/src/kw_.cpp +++ b/src/kw_.cpp @@ -600,7 +600,7 @@ wchar_t* utf8ToUnicode(const char* utf8) { const int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, utf8, len, nullptr, 0); if (sizeNeeded == 0) return nullptr; - wchar_t* unicode = (wchar_t*)calloc(sizeNeeded, sizeof(wchar_t)); + wchar_t* unicode = (wchar_t*)calloc(sizeNeeded+1, sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, utf8, len, unicode, sizeNeeded); return unicode; } diff --git a/src/kwapi.h b/src/kwapi.h index bf98dfb..a6c09e3 100644 --- a/src/kwapi.h +++ b/src/kwapi.h @@ -431,7 +431,9 @@ class kwapi : inline char* bstrToString(BSTR bstr) { if (useUtf8_) { const UINT len = SysStringLen(bstr); - if (len == 0) return nullptr; + if (len == 0) { + return _strdup(""); + } const int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, bstr, len, nullptr, 0, nullptr, nullptr); char* utf8 = (char*)calloc(sizeNeeded, sizeNeeded);