From 942ea1d46574de2d8f4cea276fccf0fd1f975b69 Mon Sep 17 00:00:00 2001 From: anders_k Date: Wed, 7 Aug 2013 23:04:23 +0000 Subject: [PATCH] Win64 fixes git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6405 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/makensisw.cpp | 2 +- Contrib/zip2exe/main.cpp | 2 +- Source/Platform.h | 11 ++++- Source/exehead/Ui.c | 2 +- Source/exehead/exec.c | 75 +++++++++++++++------------------ Source/exehead/util.c | 16 ++++--- Source/exehead/util.h | 6 ++- 7 files changed, 61 insertions(+), 53 deletions(-) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 9f580de1..80703185 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -176,7 +176,7 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam { g_sdata.hwnd=hwndDlg; HICON hIcon = LoadIcon(g_sdata.hInstance,MAKEINTRESOURCE(IDI_ICON)); - SetClassLong(hwndDlg,GCL_HICON,(long)hIcon); + SetClassLongPtr(hwndDlg,GCLP_HICON,(LONG_PTR)hIcon); // Altered by Darren Owen (DrO) on 29/9/2003 // Added in receiving of mouse and key events from the richedit control SendMessage(GetDlgItem(hwndDlg,IDC_LOGWIN),EM_SETEVENTMASK,(WPARAM)NULL,ENM_SELCHANGE|ENM_MOUSEEVENTS|ENM_KEYEVENTS); diff --git a/Contrib/zip2exe/main.cpp b/Contrib/zip2exe/main.cpp index ec38fdc3..4f64a17d 100644 --- a/Contrib/zip2exe/main.cpp +++ b/Contrib/zip2exe/main.cpp @@ -632,7 +632,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) SetDlgItemText(hwndDlg,IDC_INSTPATH,gp_poi); hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON1)); - SetClassLong(hwndDlg,GCL_HICON,(long)hIcon); + SetClassLongPtr(hwndDlg,GCLP_HICON,(LONG_PTR)hIcon); hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, diff --git a/Source/Platform.h b/Source/Platform.h index e1d7eebb..256fe5a6 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -113,7 +113,9 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; // mingw32 and w64-mingw32 do not define ULONG_PTR // but rather declare ULONG_PTR via typedef (see basetsd.h) #if !defined(__MINGW32__) && !defined(ULONG_PTR) -# define ULONG_PTR unsigned long +# ifndef _WIN64 +# define ULONG_PTR unsigned long +# endif #endif #ifdef __cplusplus @@ -248,6 +250,13 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; # define ZeroMemory(x, y) memset(x, 0, y) #endif +#ifndef _WIN64 +# ifndef GCLP_HICON +# define GCLP_HICON GCL_HICON +# define SetClassLongPtr SetClassLong +# endif +#endif + // defines #ifndef MEM_LARGE_PAGES diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index 30f67813..7a321bc4 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -488,7 +488,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) m_hwndOK=GetDlgItem(hwndDlg,IDOK); m_hwndCancel=GetDlgItem(hwndDlg,IDCANCEL); SetDlgItemTextFromLang(hwndDlg,IDC_VERSTR,LANG_BRANDING); - SetClassLong(hwndDlg,GCL_HICON,(long)g_hIcon); + SetClassLongPtr(hwndDlg,GCLP_HICON,(LONG_PTR)g_hIcon); // use the following line instead of the above, if .rdata needs shirking //SendMessage(hwndDlg,WM_SETICON,ICON_BIG,(LPARAM)g_hIcon); #if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT) diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index e6d2793d..b30e208c 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -122,10 +122,12 @@ void NSISCALL update_status_text_buf1(int strtab) update_status_text(strtab, g_bufs[1]); } -static int NSISCALL GetIntFromParm(int id_) +static INT_PTR NSISCALL GetIntPtrFromParm(int id_) { - return myatoi(GetNSISStringTT(g_parms[id_])); + return strtoiptr(GetNSISStringTT(g_parms[id_])); } +#define GetHwndFromParm(id_) ( (HWND)GetIntPtrFromParm(id_) ) +#define GetIntFromParm(id_) ( (INT32)(UINT32)GetIntPtrFromParm(id_) ) // NB - USE CAUTION when rearranging code to make use of the new return value of // this function - be sure the parm being accessed is not modified before the call. @@ -685,7 +687,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) { int v,v2; TCHAR *p=var0; - v=GetIntFromParm(1); + v=GetIntFromParm(1); // BUGBUG64: TODO: These should be INT_PTR, the script might be playing with pointers and System::Call v2=GetIntFromParm(2); switch (parm3) { @@ -710,7 +712,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) TCHAR *buf0=GetStringFromParm(0x01); wsprintf(var0, buf0, - GetIntFromParm(2)); + GetIntPtrFromParm(2)); } break; #endif//NSIS_SUPPORT_INTOPTS @@ -758,15 +760,15 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_FINDWINDOW: case EW_SENDMESSAGE: { - int v; - int b3=GetIntFromParm(3); - int b4=GetIntFromParm(4); - if (parm5&1) b3=(int)GetStringFromParm(0x33); - if (parm5&2) b4=(int)GetStringFromParm(0x44); + LRESULT v; + INT_PTR b3=GetIntPtrFromParm(3); + INT_PTR b4=GetIntPtrFromParm(4); + if (parm5&1) b3=(INT_PTR)GetStringFromParm(0x33); + if (parm5&2) b4=(INT_PTR)GetStringFromParm(0x44); if (which == EW_SENDMESSAGE) { - HWND hwnd=(HWND)GetIntFromParm(1); + HWND hwnd=GetHwndFromParm(1); int msg=GetIntFromParm(2); if (parm5>>2) exec_error += !SendMessageTimeout(hwnd,msg,b3,b4,SMTO_NORMAL,parm5>>2,(LPDWORD)&v); @@ -779,22 +781,21 @@ static int NSISCALL ExecuteEntry(entry *entry_) { TCHAR *buf0=GetStringFromParm(0x01); TCHAR *buf1=GetStringFromParm(0x12); - v=(int)FindWindowEx((HWND)b3,(HWND)b4,buf0[0]?buf0:NULL,buf1[0]?buf1:NULL); + v=(LRESULT)FindWindowEx((HWND)b3,(HWND)b4,buf0[0]?buf0:NULL,buf1[0]?buf1:NULL); } - if (parm0>=0) - myitoa(var0,v); + if (parm0>=0) iptrtostr(var0,v); } break; case EW_ISWINDOW: - if (IsWindow((HWND)GetIntFromParm(0))) return parm1; + if (IsWindow(GetHwndFromParm(0))) return parm1; return parm2; #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT case EW_GETDLGITEM: - myitoa( + iptrtostr( var0, - (int)GetDlgItem( - (HWND)GetIntFromParm(1), + (INT_PTR)GetDlgItem( + GetHwndFromParm(1), GetIntFromParm(2) ) ); @@ -802,7 +803,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_SETCTLCOLORS: { ctlcolors *c = (ctlcolors *)(g_blocks[NB_CTLCOLORS].offset + parm1); - SetWindowLongPtr((HWND) GetIntFromParm(0), GWLP_USERDATA, (LONG_PTR) c); + SetWindowLongPtr(GetHwndFromParm(0), GWLP_USERDATA, (LONG_PTR) c); } break; case EW_SETBRANDINGIMAGE: @@ -841,12 +842,12 @@ static int NSISCALL ExecuteEntry(entry *entry_) f.lfStrikeOut=parm4&4; f.lfCharSet=DEFAULT_CHARSET; GetNSISString(f.lfFaceName,parm1); - myitoa(var0,(int)CreateFontIndirect(&f)); + iptrtostr(var0,(INT_PTR)CreateFontIndirect(&f)); } break; case EW_SHOWWINDOW: { - HWND hw=(HWND)GetIntFromParm(0); + HWND hw=GetHwndFromParm(0); int a=GetIntFromParm(1); if (parm2) log_printf(_T("HideWindow")); if (!parm3) @@ -1077,7 +1078,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef _UNICODE hres = ppf->lpVtbl->Save(ppf,buf1,TRUE); #else - WCHAR *wsz = (LPWSTR) buf2; // buf2...buf3 = WCHAR wsz[NSIS_MAX_STRLEN] + WCHAR *wsz = (LPWSTR) buf2; // buf2 + buf3 = WCHAR wsz[NSIS_MAX_STRLEN] hres = E_FAIL; if (MultiByteToWideChar(CP_ACP,0,buf1,-1,wsz,NSIS_MAX_STRLEN)) hres = ppf->lpVtbl->Save(ppf,wsz,TRUE); @@ -1162,18 +1163,9 @@ static int NSISCALL ExecuteEntry(entry *entry_) mystrcpy(buf1,_T("")); mystrcpy(buf2,buf1); #endif - if (parm0) - { - sec=GetStringFromParm(0x00); - } - if (parm1) - { - key=GetStringFromParm(0x11); - } - if (parm4) - { - str=GetStringFromParm(0x22); - } + if (parm0) sec=GetStringFromParm(0x00); + if (parm1) key=GetStringFromParm(0x11); + if (parm4) str=GetStringFromParm(0x22); buf3=GetStringFromParm(-0x33); log_printf5(_T("WriteINIStr: wrote [%s] %s=%s in %s"),buf0,buf1,buf2,buf3); if (!WritePrivateProfileString(sec,key,str,buf3)) exec_error++; @@ -1346,7 +1338,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_FCLOSE: { TCHAR *t=var0; - if (*t) CloseHandle((HANDLE)myatoi(t)); + if (*t) CloseHandle((HANDLE)strtoiptr(t)); } break; case EW_FOPEN: @@ -1362,7 +1354,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) } else { - myitoa(handleout,(int)h); + iptrtostr(handleout,(INT_PTR)h); } } break; @@ -1393,7 +1385,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) { l=mystrlen(GetStringFromParm(0x11))*sizeof(TCHAR); } - if (!*t || !WriteFile((HANDLE)myatoi(t),buf1,l,&dw,NULL)) + if (!*t || !WriteFile((HANDLE)strtoiptr(t),buf1,l,&dw,NULL)) { exec_error++; } @@ -1414,7 +1406,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) if (*hptr) { TCHAR lc=0; - HANDLE h=(HANDLE)myatoi(hptr); + HANDLE h=(HANDLE)strtoiptr(hptr); while (rpos 4GB support on _WIN64 + DWORD v=SetFilePointer((HANDLE)strtoiptr(t),GetIntFromParm(2),NULL,parm3); if (parm1>=0) { @@ -1482,7 +1475,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) case EW_FINDCLOSE: { TCHAR *t=var0; - if (*t) FindClose((HANDLE)myatoi(t)); + if (*t) FindClose((HANDLE)strtoiptr(t)); } break; case EW_FINDNEXT: @@ -1490,7 +1483,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) TCHAR *textout=var0; TCHAR *t=var1; WIN32_FIND_DATA fd; - if (*t && FindNextFile((HANDLE)myatoi(t),&fd)) + if (*t && FindNextFile((HANDLE)strtoiptr(t),&fd)) { mystrcpy(textout,fd.cFileName); } @@ -1518,7 +1511,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) } else { - myitoa(handleout,(int)h); + iptrtostr(handleout,(INT_PTR)h); mystrcpy(textout,fd.cFileName); } } diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 81cb2ef7..c79468ec 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -603,16 +603,20 @@ void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR } } -void NSISCALL myitoa(TCHAR *s, int d) +void NSISCALL iptrtostr(TCHAR *s, INT_PTR d) { +#ifdef _WIN64 + static const TCHAR c[] = _T("%I64d"); +#else static const TCHAR c[] = _T("%d"); +#endif wsprintf(s,c,d); } -int NSISCALL myatoi(TCHAR *s) +INT_PTR NSISCALL strtoiptr(const TCHAR *s) { - unsigned int v=0; - int sign=1; // sign of positive + UINT_PTR v=0; + INT_PTR sign=1; // sign of positive TCHAR m=10; // base of 10 TCHAR t=_T('9'); // cap top of numbers at 9 @@ -647,7 +651,7 @@ int NSISCALL myatoi(TCHAR *s) v*=m; v+=c; } - return ((int)v)*sign; + return ((INT_PTR)v)*sign; } // Straight copies of selected shell functions. Calling local functions @@ -813,7 +817,7 @@ TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab) else if (nVarIdx == NS_VAR_CODE) { if (nData == 29) // $HWNDPARENT - myitoa(out, (unsigned int) g_hwnd); + iptrtostr(out, (INT_PTR) g_hwnd); else mystrcpy(out, g_usrvars[nData]); // validate the directory name diff --git a/Source/exehead/util.h b/Source/exehead/util.h index f0c46b31..dd3b3ad6 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -33,8 +33,10 @@ TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab); #define GetNSISTab(strtab) (strtab < 0 ? LANG_STR_TAB(strtab) : strtab) void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR *out, int x64); -int NSISCALL myatoi(TCHAR *s); -void NSISCALL myitoa(TCHAR *s, int d); +#define myatoi(s) ( (int)strtoiptr(s) ) +INT_PTR NSISCALL strtoiptr(const TCHAR *s); +#define myitoa iptrtostr +void NSISCALL iptrtostr(TCHAR *s, INT_PTR d); TCHAR * NSISCALL mystrcpy(TCHAR *out, const TCHAR *in); int NSISCALL mystrlen(const TCHAR *in); TCHAR * NSISCALL mystrcat(TCHAR *out, const TCHAR *concat);