StrSafe adaptions

This commit is contained in:
Rainer Kottenhoff 2017-08-21 18:02:50 +02:00
parent 399efd2de2
commit 3db1dbd0ab
5 changed files with 55 additions and 56 deletions

View File

@ -53,8 +53,8 @@ extern WCHAR szCurFile[MAX_PATH+40];
int MsgBox(int iType,UINT uIdMsg,...)
{
WCHAR szText [1024];
WCHAR szBuf [1024];
WCHAR szText [HUGE_BUFFER];
WCHAR szBuf [HUGE_BUFFER];
WCHAR szTitle[64];
int iIcon = 0;
HWND hwnd;
@ -62,7 +62,7 @@ int MsgBox(int iType,UINT uIdMsg,...)
if (!GetString(uIdMsg,szBuf,COUNTOF(szBuf)))
return(0);
wvsprintf(szText,szBuf,(LPVOID)((PUINT_PTR)&uIdMsg + 1));
StringCchVPrintfW(szText,COUNTOF(szText),szBuf,(LPVOID)((PUINT_PTR)&uIdMsg + 1));
if (uIdMsg == IDS_ERR_LOADFILE || uIdMsg == IDS_ERR_SAVEFILE ||
uIdMsg == IDS_CREATEINI_FAIL || uIdMsg == IDS_WRITEINI_FAIL ||
@ -160,17 +160,16 @@ BOOL GetDirectory(HWND hwndParent,int iTitle,LPWSTR pszFolder,LPCWSTR pszBase,BO
BROWSEINFO bi;
LPITEMIDLIST pidl;
WCHAR szTitle[256] = { L'\0' };;
WCHAR szTitle[MIDSZ_BUFFER] = { L'\0' };;
WCHAR szBase[MAX_PATH] = { L'\0' };
BOOL fOk = FALSE;
lstrcpy(szTitle,L"");
GetString(iTitle,szTitle,COUNTOF(szTitle));
if (!pszBase || !*pszBase)
GetCurrentDirectory(MAX_PATH,szBase);
else
lstrcpy(szBase,pszBase);
StringCchCopy(szBase,COUNTOF(szBase),pszBase);
bi.hwndOwner = hwndParent;
bi.pidlRoot = NULL;
@ -361,8 +360,8 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
PathQuoteSpaces(szFile);
if (lstrlen(szArg2))
{
lstrcat(szFile,L" ");
lstrcat(szFile,szArg2);
StringCchCat(szFile,COUNTOF(szFile),L" ");
StringCchCat(szFile,COUNTOF(szFile),szArg2);
}
SetDlgItemText(hwnd,IDC_COMMANDLINE,szFile);
}
@ -407,7 +406,7 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
}
if (lstrlen(szCurFile)) {
lstrcpy(wchDirectory,szCurFile);
StringCchCopy(wchDirectory,COUNTOF(wchDirectory),szCurFile);
PathRemoveFileSpec(wchDirectory);
}
@ -640,7 +639,7 @@ BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile)
WCHAR wchDirectory[MAX_PATH] = { L'\0' };
if (lstrlen(szCurFile)) {
lstrcpy(wchDirectory,szCurFile);
StringCchCopy(wchDirectory,COUNTOF(wchDirectory),szCurFile);
PathRemoveFileSpec(wchDirectory);
}
@ -656,7 +655,7 @@ BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile)
// resolve links and get short path name
if (!(PathIsLnkFile(lpstrFile) && PathGetLnkPath(lpstrFile,szParam,COUNTOF(szParam))))
lstrcpy(szParam,lpstrFile);
StringCchCopy(szParam,COUNTOF(szParam),lpstrFile);
//GetShortPathName(szParam,szParam,sizeof(WCHAR)*COUNTOF(szParam));
PathQuoteSpaces(szParam);
@ -916,7 +915,7 @@ BOOL AddToFavDlg(HWND hwnd,LPCWSTR lpszName,LPCWSTR lpszTarget)
INT_PTR iResult;
WCHAR pszName[MAX_PATH] = { L'\0' };
lstrcpy(pszName,lpszName);
StringCchCopy(pszName,COUNTOF(pszName),lpszName);
iResult = ThemedDialogBoxParam(
g_hInstance,
@ -1325,7 +1324,7 @@ INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
}
else {
lstrcpy((LPWSTR)GetWindowLongPtr(hwnd,DWLP_USER),tch);
StringCchCopy((LPWSTR)GetWindowLongPtr(hwnd,DWLP_USER),MAX_PATH,tch);
EndDialog(hwnd,IDOK);
}
}
@ -1556,7 +1555,7 @@ INT_PTR CALLBACK WordWrapSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
for (i = 0; i < 4; i++) {
GetDlgItemText(hwnd,200+i,tch,COUNTOF(tch));
lstrcat(tch,L"|");
StringCchCat(tch,COUNTOF(tch),L"|");
p1 = tch;
p2 = StrChr(p1, L'|');
while (p2) {
@ -2309,7 +2308,7 @@ INT_PTR InfoBox(int iType,LPCWSTR lpstrSetting,int uidMessage,...)
HWND hwnd;
int idDlg = IDD_INFOBOX;
INFOBOX ib;
WCHAR wchFormat[512];
WCHAR wchFormat[LARGE_BUFFER];
int iMode;
iMode = IniGetInt(L"Suppressed Messages",lpstrSetting,0);
@ -2320,8 +2319,8 @@ INT_PTR InfoBox(int iType,LPCWSTR lpstrSetting,int uidMessage,...)
if (!GetString(uidMessage,wchFormat,COUNTOF(wchFormat)))
return(-1);
ib.lpstrMessage = LocalAlloc(LPTR,1024 * sizeof(WCHAR));
wvsprintf(ib.lpstrMessage,wchFormat,(LPVOID)((PUINT_PTR)&uidMessage + 1));
ib.lpstrMessage = LocalAlloc(LPTR, HUGE_BUFFER * sizeof(WCHAR));
StringCchVPrintfW(ib.lpstrMessage,HUGE_BUFFER,wchFormat,(LPVOID)((PUINT_PTR)&uidMessage + 1));
ib.lpstrSetting = (LPWSTR)lpstrSetting;
ib.bDisableCheckBox = (lstrlen(szIniFile) == 0 || lstrlen(lpstrSetting) == 0 || iMode == 2) ? TRUE : FALSE;

View File

@ -71,7 +71,7 @@ BOOL DirList_Init(HWND hwnd,LPCWSTR pszHeader)
lpdl->cbidl = 0;
lpdl->pidl = NULL;
lpdl->lpsf = NULL;
lstrcpy(lpdl->szPath,L"");
StringCchCopy(lpdl->szPath,MAX_PATH,L"");
// Add Imagelists
hil = (HIMAGELIST)SHGetFileInfo(L"C:\\",0,&shfi,sizeof(SHFILEINFO),
@ -240,7 +240,7 @@ int DirList_Fill(HWND hwnd,LPCWSTR lpszDir,DWORD grfFlags,LPCWSTR lpszFileSpec,
if (!lpszDir || !*lpszDir)
return(-1);
lstrcpy(lpdl->szPath,lpszDir);
StringCchCopy(lpdl->szPath,MAX_PATH,lpszDir);
// Init ListView
SendMessage(hwnd,WM_SETREDRAW,0,0);
@ -264,8 +264,7 @@ int DirList_Fill(HWND hwnd,LPCWSTR lpszDir,DWORD grfFlags,LPCWSTR lpszFileSpec,
-1,
wszDir,
MAX_PATH);*/
lstrcpy(wszDir,lpszDir);
StringCchCopy(wszDir,COUNTOF(wszDir),lpszDir);
// Get Desktop Folder
if (NOERROR == SHGetDesktopFolder(&lpsfDesktop))
@ -878,13 +877,13 @@ BOOL DirList_PropertyDlg(HWND hwnd,int iItem)
//
// Get long pathname for currently displayed directory
//
BOOL DirList_GetLongPathName(HWND hwnd,LPWSTR lpszLongPath)
BOOL DirList_GetLongPathName(HWND hwnd,LPWSTR lpszLongPath,int length)
{
WCHAR tch[MAX_PATH] = { L'\0' };
LPDLDATA lpdl = (LPVOID)GetProp(hwnd,pDirListProp);
if (SHGetPathFromIDList(lpdl->pidl,tch))
{
lstrcpy(lpszLongPath,tch);
StringCchCopy(lpszLongPath,length,tch);
return(TRUE);
}
else

View File

@ -125,7 +125,7 @@ BOOL DirList_PropertyDlg(HWND,int);
//==== DlGetLongPathName() ====================================================
BOOL DirList_GetLongPathName(HWND,LPWSTR);
BOOL DirList_GetLongPathName(HWND,LPWSTR,int);
//==== DlSelectItem() =========================================================

View File

@ -555,7 +555,7 @@ BOOL EditCopyAppend(HWND hwnd)
if (cchTextW > 0) {
int lenTxt = (lstrlen(pszSep) + cchTextW + 1);
pszTextW = LocalAlloc(LPTR,sizeof(WCHAR)*lenTxt);
StringCchCopyW(pszTextW,lenTxt,pszSep);
StringCchCopy(pszTextW,lenTxt,pszSep);
MultiByteToWideChar(uCodePage,0,pszText,-1,StrEnd(pszTextW),(int)LocalSize(pszTextW)/sizeof(WCHAR));
}
else {
@ -576,8 +576,8 @@ BOOL EditCopyAppend(HWND hwnd)
hNew = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * sizeNew);
pszNew = GlobalLock(hNew);
StringCchCopyW(pszNew,sizeNew,pszOld);
StringCchCatW(pszNew,sizeNew,pszTextW);
StringCchCopy(pszNew,sizeNew,pszOld);
StringCchCat(pszNew,sizeNew,pszTextW);
GlobalUnlock(hNew);
GlobalUnlock(hOld);
@ -801,9 +801,9 @@ void Encoding_AddToListView(HWND hwnd,int idSel,BOOL bRecodeOnly)
StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf));
if (Encoding_IsANSI(id))
StringCchCatNW(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI));
StringCchCatN(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI));
else if (id == CPI_OEM)
StringCchCatNW(wchBuf,COUNTOF(wchBuf),wchOEM,COUNTOF(wchOEM));
StringCchCatN(wchBuf,COUNTOF(wchBuf),wchOEM,COUNTOF(wchOEM));
if ((mEncoding[id].uFlags & NCP_INTERNAL) ||
(IsValidCodePage(mEncoding[id].uCodePage) &&
@ -894,9 +894,9 @@ void Encoding_AddToComboboxEx(HWND hwnd,int idSel,BOOL bRecodeOnly)
StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf));
if (Encoding_IsANSI(id))
StringCchCatNW(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI));
StringCchCatN(wchBuf,COUNTOF(wchBuf),wchANSI,COUNTOF(wchANSI));
else if (id == CPI_OEM)
StringCchCatNW(wchBuf,COUNTOF(wchBuf),wchOEM,COUNTOF(wchOEM));
StringCchCatN(wchBuf,COUNTOF(wchBuf),wchOEM,COUNTOF(wchOEM));
if ((mEncoding[id].uFlags & NCP_INTERNAL) ||
(IsValidCodePage(mEncoding[id].uCodePage) &&
@ -2880,7 +2880,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
if (StrCmpNA(p,"$(I)",CSTRLEN("$(I)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(I)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(I)"));
bPrefixNum = TRUE;
iPrefixNum = 0;
for (i = iLineEnd - iLineStart; i >= 10; i = i / 10)
@ -2890,7 +2890,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0I)",CSTRLEN("$(0I)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(0I)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(0I)"));
bPrefixNum = TRUE;
iPrefixNum = 0;
for (i = iLineEnd - iLineStart; i >= 10; i = i / 10)
@ -2900,7 +2900,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(N)",CSTRLEN("$(N)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(N)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(N)"));
bPrefixNum = TRUE;
iPrefixNum = 1;
for (i = iLineEnd - iLineStart + 1; i >= 10; i = i / 10)
@ -2910,7 +2910,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0N)",CSTRLEN("$(0N)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(0N)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(0N)"));
bPrefixNum = TRUE;
iPrefixNum = 1;
for (i = iLineEnd - iLineStart + 1; i >= 10; i = i / 10)
@ -2920,7 +2920,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(L)",CSTRLEN("$(L)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(L)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(L)"));
bPrefixNum = TRUE;
iPrefixNum = iLineStart+1;
for (i = iLineEnd + 1; i >= 10; i = i / 10)
@ -2930,7 +2930,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0L)",CSTRLEN("$(0L)")) == 0) {
*p = 0;
StrCpyA(mszPrefix2,p+CSTRLEN("$(0L)"));
StringCchCopyA(mszPrefix2,COUNTOF(mszPrefix2),p + CSTRLEN("$(0L)"));
bPrefixNum = TRUE;
iPrefixNum = iLineStart+1;
for (i = iLineEnd + 1; i >= 10; i = i / 10)
@ -2949,7 +2949,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
if (StrCmpNA(p,"$(I)",CSTRLEN("$(I)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(I)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(I)"));
bAppendNum = TRUE;
iAppendNum = 0;
for (i = iLineEnd - iLineStart; i >= 10; i = i / 10)
@ -2959,7 +2959,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0I)",CSTRLEN("$(0I)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(0I)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(0I)"));
bAppendNum = TRUE;
iAppendNum = 0;
for (i = iLineEnd - iLineStart; i >= 10; i = i / 10)
@ -2969,7 +2969,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(N)",CSTRLEN("$(N)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(N)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(N)"));
bAppendNum = TRUE;
iAppendNum = 1;
for (i = iLineEnd - iLineStart + 1; i >= 10; i = i / 10)
@ -2979,7 +2979,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0N)",CSTRLEN("$(0N)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(0N)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(0N)"));
bAppendNum = TRUE;
iAppendNum = 1;
for (i = iLineEnd - iLineStart + 1; i >= 10; i = i / 10)
@ -2989,7 +2989,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(L)",CSTRLEN("$(L)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(L)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(L)"));
bAppendNum = TRUE;
iAppendNum = iLineStart+1;
for (i = iLineEnd + 1; i >= 10; i = i / 10)
@ -2999,7 +2999,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
else if (StrCmpNA(p,"$(0L)",CSTRLEN("$(0L)")) == 0) {
*p = 0;
StrCpyA(mszAppend2,p+CSTRLEN("$(0L)"));
StringCchCopyA(mszAppend2,COUNTOF(mszAppend2),p + CSTRLEN("$(0L)"));
bAppendNum = TRUE;
iAppendNum = iLineStart+1;
for (i = iLineEnd + 1; i >= 10; i = i / 10)
@ -3020,15 +3020,15 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
if (lstrlen(pwszPrefix)) {
char mszInsert[512*3];
lstrcpyA(mszInsert,mszPrefix1);
StringCchCopyA(mszInsert,COUNTOF(mszInsert),mszPrefix1);
if (bPrefixNum) {
char tchFmt[64];
char tchNum[64];
StringCchPrintfA(tchFmt,COUNTOF(tchFmt),"%%%s%ii",pszPrefixNumPad,iPrefixNumWidth);
StringCchPrintfA(tchNum,COUNTOF(tchNum),tchFmt,iPrefixNum);
lstrcatA(mszInsert,tchNum);
lstrcatA(mszInsert,mszPrefix2);
StringCchCatA(mszInsert,COUNTOF(mszInsert),tchNum);
StringCchCatA(mszInsert,COUNTOF(mszInsert),mszPrefix2);
iPrefixNum++;
}
iPos = (int)SendMessage(hwnd,SCI_POSITIONFROMLINE,(WPARAM)iLine,0);
@ -3040,15 +3040,15 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend)
if (lstrlen(pwszAppend)) {
char mszInsert[512*3];
lstrcpyA(mszInsert,mszAppend1);
StringCchCopyA(mszInsert,COUNTOF(mszInsert),mszAppend1);
if (bAppendNum) {
char tchFmt[64];
char tchNum[64];
StringCchPrintfA(tchFmt,COUNTOF(tchFmt),"%%%s%ii",pszAppendNumPad,iAppendNumWidth);
StringCchPrintfA(tchNum,COUNTOF(tchNum),tchFmt,iAppendNum);
lstrcatA(mszInsert,tchNum);
lstrcatA(mszInsert,mszAppend2);
StringCchCatA(mszInsert,COUNTOF(mszInsert),tchNum);
StringCchCatA(mszInsert,COUNTOF(mszInsert),mszAppend2);
iAppendNum++;
}
iPos = (int)SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0);
@ -3235,8 +3235,9 @@ void EditAlignText(HWND hwnd,int nMode)
int i,j;
int iPos;
WCHAR wchNewLineBuf[BUFSIZE_ALIGN*3];
StrCpy(wchNewLineBuf,pWords[0]);
WCHAR wchNewLineBuf[BUFSIZE_ALIGN * 3] = { L'\0' };
int length = BUFSIZE_ALIGN * 3;
StringCchCopy(wchNewLineBuf,COUNTOF(wchNewLineBuf),pWords[0]);
p = StrEnd(wchNewLineBuf);
for (i = 1; i < iWords; i++) {
@ -3248,7 +3249,7 @@ void EditAlignText(HWND hwnd,int nMode)
*p++ = L' ';
*p = 0;
}
StrCat(p,pWords[i]);
StringCchCat(p,(length - lstrlen(wchNewLineBuf)),pWords[i]);
p = StrEnd(p);
}
@ -3267,14 +3268,14 @@ void EditAlignText(HWND hwnd,int nMode)
int i;
int iPos;
WCHAR wchNewLineBuf[BUFSIZE_ALIGN];
StrCpy(wchNewLineBuf,pWords[0]);
WCHAR wchNewLineBuf[BUFSIZE_ALIGN] = { L'\0' };
StringCchCopy(wchNewLineBuf,COUNTOF(wchNewLineBuf),pWords[0]);
p = StrEnd(wchNewLineBuf);
for (i = 1; i < iWords; i++) {
*p++ = L' ';
*p = 0;
StrCat(wchNewLineBuf,pWords[i]);
StringCchCat(p,(BUFSIZE_ALIGN - lstrlen(wchNewLineBuf)),pWords[i]);
p = StrEnd(p);
}

View File

@ -16,7 +16,7 @@
#ifndef _NP3_HELPERS_H_
#define _NP3_HELPERS_H_
#define STRSAFE_NO_DEPRECATE // comment out to see missing migrations
//#define STRSAFE_NO_DEPRECATE // comment out to see missing migrations
#define STRSAFE_NO_CB_FUNCTIONS
#include <strsafe.h>