+ rfc: static string buffer -> dynamic memory allocation

This commit is contained in:
Rainer Kottenhoff 2021-02-26 09:20:39 +01:00
parent e4fb050599
commit 13fbdcd5df
3 changed files with 18 additions and 17 deletions

View File

@ -445,15 +445,19 @@ int LoadLngStringW(UINT uID, LPWSTR lpBuffer, int nBufferMax)
//
// LoadLngStringW2MB()
//
static WCHAR s_tmpStringBuffer[512];
ptrdiff_t LoadLngStringW2MB(UINT uID, LPSTR lpBuffer, int nBufferMax)
int LoadLngStringW2MB(UINT uID, LPSTR lpBuffer, int nBufferMax)
{
const int nLen = LoadStringW(Globals.hLngResContainer, uID, s_tmpStringBuffer, COUNTOF(s_tmpStringBuffer));
if (nLen == 0) {
LoadStringW(Globals.hInstance, uID, s_tmpStringBuffer, COUNTOF(s_tmpStringBuffer));
int len = 0;
WCHAR * const pBuffer = (WCHAR *)AllocMem(sizeof(WCHAR) * nBufferMax, HEAP_ZERO_MEMORY);
if (pBuffer) {
const int nLen = LoadStringW(Globals.hLngResContainer, uID, pBuffer, nBufferMax);
if (nLen == 0) {
LoadStringW(Globals.hInstance, uID, pBuffer, nBufferMax);
}
len = WideCharToMultiByte(Encoding_SciCP, 0, pBuffer, -1, lpBuffer, nBufferMax, NULL, NULL);
FreeMem(pBuffer);
}
return WideCharToMultiByteEx(CP_UTF8, 0, s_tmpStringBuffer, -1, lpBuffer, nBufferMax, NULL, NULL);
return len;
}
//=============================================================================
@ -473,7 +477,7 @@ int LoadLngStringA(UINT uID, LPSTR lpBuffer, int nBufferMax)
//
int FormatLngStringW(LPWSTR lpOutput, int nOutput, UINT uIdFormat, ...)
{
WCHAR* pBuffer = AllocMem(sizeof(WCHAR) * nOutput, HEAP_ZERO_MEMORY);
WCHAR* const pBuffer = AllocMem(sizeof(WCHAR) * nOutput, HEAP_ZERO_MEMORY);
if (pBuffer) {
if (LoadLngStringW(uIdFormat, pBuffer, nOutput)) {
StringCchVPrintfW(lpOutput, nOutput, pBuffer, (LPVOID)((PUINT_PTR)& uIdFormat + 1));
@ -490,7 +494,7 @@ int FormatLngStringW(LPWSTR lpOutput, int nOutput, UINT uIdFormat, ...)
//
int FormatLngStringA(LPSTR lpOutput, int nOutput, UINT uIdFormat, ...)
{
CHAR* pBuffer = AllocMem(sizeof(CHAR) * nOutput, HEAP_ZERO_MEMORY);
CHAR* const pBuffer = AllocMem(sizeof(CHAR) * nOutput, HEAP_ZERO_MEMORY);
if (pBuffer) {
if (LoadLngStringA(uIdFormat, pBuffer, nOutput)) {
StringCchVPrintfA(lpOutput, nOutput, pBuffer, (LPVOID)((PUINT_PTR)& uIdFormat + 1));

View File

@ -55,7 +55,7 @@ int LoadLngStringW(UINT uID, LPWSTR lpBuffer, int nBufferMax);
int LoadLngStringA(UINT uID, LPSTR lpBuffer, int nBufferMax);
int FormatLngStringW(LPWSTR lpOutput, int nOutput, UINT uIdFormat, ...);
int FormatLngStringA(LPSTR lpOutput, int nOutput, UINT uIdFormat, ...);
ptrdiff_t LoadLngStringW2MB(UINT uID, LPSTR lpBuffer, int nBufferMax);
int LoadLngStringW2MB(UINT uID, LPSTR lpBuffer, int nBufferMax);
#define GetLngString(id,pb,cb) LoadLngStringW((id),(pb),(cb))
#define GetLngStringA(id,pb,cb) LoadLngStringA((id),(pb),(cb))

View File

@ -6939,18 +6939,15 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
break;
}
WCHAR wchCalltipAdd[SMALL_BUFFER] = { L'\0' };
CHAR chCalltipAdd[LARGE_BUFFER] = { L'\0' };
if (StrStrIA(chText, "file:") == chText) {
GetLngString(IDS_MUI_URL_OPEN_FILE, wchCalltipAdd, COUNTOF(wchCalltipAdd));
GetLngStringW2MB(IDS_MUI_URL_OPEN_FILE, chCalltipAdd, COUNTOF(chCalltipAdd));
} else {
GetLngString(IDS_MUI_URL_OPEN_BROWSER, wchCalltipAdd, COUNTOF(wchCalltipAdd));
GetLngStringW2MB(IDS_MUI_URL_OPEN_BROWSER, chCalltipAdd, COUNTOF(chCalltipAdd));
}
CHAR chAdd[LARGE_BUFFER] = { L'\0' };
WideCharToMultiByte(Encoding_SciCP, 0, wchCalltipAdd, -1, chAdd, (int)COUNTOF(chAdd), NULL, NULL);
char chCallTip[HUGE_BUFFER] = { '\0' };
StringCchCatA(chCallTip, COUNTOF(chCallTip), chText);
StringCchCatA(chCallTip, COUNTOF(chCallTip), chAdd);
StringCchCatA(chCallTip, COUNTOF(chCallTip), chCalltipAdd);
//SciCall_CallTipSetPosition(true);
SciCall_CallTipShow(position, chCallTip);
SciCall_CallTipSetHlt(0, (int)length);