diff --git a/src/CWebBrowser/CWebBrowser.c b/src/CWebBrowser/CWebBrowser.c index 0d54370..eaa9256 100644 --- a/src/CWebBrowser/CWebBrowser.c +++ b/src/CWebBrowser/CWebBrowser.c @@ -1491,7 +1491,7 @@ // // call EmbedBrowserObject() for each one, and easily associate the appropriate browser object with // // its matching window and its own objects containing per-window data. // *((IOleObject **)ptr) = browserObject; -// SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)ptr); +// SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ptr); // // // Give the browser a pointer to my IOleClientSite object // if (!browserObject->lpVtbl->SetClientSite(browserObject, (IOleClientSite *)_iOleClientSiteEx)) diff --git a/src/EterBase/Singleton.h b/src/EterBase/Singleton.h index 1b5924c..23da6ae 100644 --- a/src/EterBase/Singleton.h +++ b/src/EterBase/Singleton.h @@ -11,8 +11,8 @@ public: CSingleton() { assert(!ms_singleton); - int offset = (int) (T*) 1 - (int) (CSingleton *) (T*) 1; - ms_singleton = (T*) ((int) this + offset); + intptr_t offset = (intptr_t) (T*) 1 - (intptr_t) (CSingleton *) (T*) 1; + ms_singleton = (T*) ((intptr_t) this + offset); } virtual ~CSingleton() @@ -52,8 +52,8 @@ public: singleton() { assert(!ms_singleton); - int offset = (int) (T*) 1 - (int) (singleton *) (T*) 1; - ms_singleton = (T*) ((int) this + offset); + intptr_t offset = (intptr_t) (T*) 1 - (intptr_t) (singleton *) (T*) 1; + ms_singleton = (T*) ((intptr_t) this + offset); } virtual ~singleton() diff --git a/src/EterBase/lzo.cpp b/src/EterBase/lzo.cpp index 3c51264..2cbb903 100644 --- a/src/EterBase/lzo.cpp +++ b/src/EterBase/lzo.cpp @@ -259,48 +259,54 @@ private: bool CLZObject::Decompress(DWORD * pdwKey) { - UINT uiSize; - int r; - - if (m_pHeader->dwEncryptSize) - { - DecryptBuffer buf(m_pHeader->dwEncryptSize); + int r; + lzo_uint out_len = static_cast(m_dwBufferSize); // capacity of m_pbBuffer + + if (m_pHeader->dwEncryptSize) + { + DecryptBuffer buf(m_pHeader->dwEncryptSize); + BYTE* pbDecryptedBuffer = static_cast(buf.GetBufferPtr()); - BYTE* pbDecryptedBuffer = (BYTE*)buf.GetBufferPtr(); - __Decrypt(pdwKey, pbDecryptedBuffer); - - if (*(DWORD *) pbDecryptedBuffer != ms_dwFourCC) + + if (*reinterpret_cast(pbDecryptedBuffer) != ms_dwFourCC) { TraceError("LZObject: key incorrect"); return false; } - - if (LZO_E_OK != (r = lzo1x_decompress(pbDecryptedBuffer + sizeof(DWORD), m_pHeader->dwCompressedSize, m_pbBuffer, (lzo_uint*) &uiSize, NULL))) - { - TraceError("LZObject: Decompress failed(decrypt) ret %d\n", r); - return false; - } - } - else - { - uiSize = m_pHeader->dwRealSize; - - //if (LZO_E_OK != (r = lzo1x_decompress_safe(m_pbIn, m_pHeader->dwCompressedSize, m_pbBuffer, (lzo_uint*) &uiSize, NULL))) - if (LZO_E_OK != (r = lzo1x_decompress(m_pbIn, m_pHeader->dwCompressedSize, m_pbBuffer, (lzo_uint*) &uiSize, NULL))) - { - TraceError("LZObject: Decompress failed : ret %d, CompressedSize %d\n", r, m_pHeader->dwCompressedSize); - return false; - } - } - - if (uiSize != m_pHeader->dwRealSize) - { + + r = lzo1x_decompress_safe( + pbDecryptedBuffer + sizeof(DWORD), + static_cast(m_pHeader->dwCompressedSize), + m_pbBuffer, + &out_len, + nullptr); + } + else + { + out_len = static_cast(m_dwBufferSize); // reset capacity + r = lzo1x_decompress_safe( + m_pbIn, + static_cast(m_pHeader->dwCompressedSize), + m_pbBuffer, + &out_len, + nullptr); + } + + if (r != LZO_E_OK) + { + TraceError("LZObject: Decompress failed: ret %d, CompressedSize %u", + r, m_pHeader->dwCompressedSize); + return false; + } + + if (out_len != static_cast(m_pHeader->dwRealSize)) + { TraceError("LZObject: Size differs"); return false; - } - - return true; + } + + return true; } bool CLZObject::Encrypt(DWORD * pdwKey) diff --git a/src/EterLib/MSWindow.cpp b/src/EterLib/MSWindow.cpp index 57e3adb..f446d4e 100644 --- a/src/EterLib/MSWindow.cpp +++ b/src/EterLib/MSWindow.cpp @@ -79,7 +79,7 @@ bool CMSWindow::Create(const char* c_szName, int brush, DWORD cs, DWORD ws, HICO if (!m_hWnd) return false; - SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (DWORD) this); + SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR)this); //DestroyWindow(ImmGetDefaultIMEWnd(m_hWnd)); return true; diff --git a/src/EterLib/Util.cpp b/src/EterLib/Util.cpp index 787ee32..bcb6ced 100644 --- a/src/EterLib/Util.cpp +++ b/src/EterLib/Util.cpp @@ -248,17 +248,14 @@ const char * GetDefaultFontFace() const char* GetFontFaceFromCodePage(WORD codePage) { - LOGFONT logFont; - - memset(&logFont, 0, sizeof(logFont)); - + LOGFONTA logFont = {}; logFont.lfCharSet = GetCharsetFromCodePage(codePage); const char* fontFace = GetFontFaceFromCodePage9x(codePage); - HDC hDC=GetDC(NULL); + HDC hDC = GetDC(NULL); - if(EnumFontFamiliesEx(hDC, &logFont, (FONTENUMPROC)EnumFontFamExProc, (LONG)fontFace, 0) == 0) + if(EnumFontFamiliesEx(hDC, &logFont, EnumFontFamExProc, (LPARAM)fontFace, 0) == 0) { ReleaseDC(NULL, hDC); return fontFace; @@ -266,7 +263,7 @@ const char* GetFontFaceFromCodePage(WORD codePage) fontFace = GetFontFaceFromCodePageNT(codePage); - if(EnumFontFamiliesEx(hDC, &logFont, (FONTENUMPROC)EnumFontFamExProc, (LONG)fontFace, 0) == 0) + if(EnumFontFamiliesEx(hDC, &logFont, EnumFontFamExProc, (LPARAM)fontFace, 0) == 0) { ReleaseDC(NULL, hDC); return fontFace; diff --git a/src/EterPythonLib/PythonGraphicImageModule.cpp b/src/EterPythonLib/PythonGraphicImageModule.cpp index 369fd89..ea31360 100644 --- a/src/EterPythonLib/PythonGraphicImageModule.cpp +++ b/src/EterPythonLib/PythonGraphicImageModule.cpp @@ -2,9 +2,9 @@ bool PyTuple_GetImageInstance(PyObject* poArgs, int pos, CGraphicImageInstance** ppRetImageInstance) { - int handle; + unsigned long long handle; - if (!PyTuple_GetInteger(poArgs, pos, &handle)) + if (!PyTuple_GetUnsignedLongLong(poArgs, pos, &handle)) return false; if (!handle) @@ -16,9 +16,9 @@ bool PyTuple_GetImageInstance(PyObject* poArgs, int pos, CGraphicImageInstance** bool PyTuple_GetExpandedImageInstance(PyObject* poArgs, int pos, CGraphicExpandedImageInstance ** ppRetImageInstance) { - int handle; + unsigned long long handle; - if (!PyTuple_GetInteger(poArgs, pos, &handle)) + if (!PyTuple_GetUnsignedLongLong(poArgs, pos, &handle)) return false; if (!handle) @@ -40,7 +40,7 @@ PyObject* grpImageGenerate(PyObject * poSelf, PyObject* poArgs) return Py_BadArgument(); if (!*szFileName) - return Py_BuildValue("i", 0); + return Py_BuildValue("K", 0); CResource * pResource = CResourceManager::Instance().GetResourcePointer(szFileName); @@ -53,7 +53,7 @@ PyObject* grpImageGenerate(PyObject * poSelf, PyObject* poArgs) if (pImageInstance->IsEmpty()) return Py_BuildException("Cannot load image (filename: %s)", szFileName); - return Py_BuildValue("i", pImageInstance); + return Py_BuildValue("K", pImageInstance); } PyObject* grpImageGenerateExpanded(PyObject* poSelf, PyObject* poArgs) @@ -64,7 +64,7 @@ PyObject* grpImageGenerateExpanded(PyObject* poSelf, PyObject* poArgs) return Py_BadArgument(); if (strlen(szFileName) <= 0) - return Py_BuildValue("i", 0); + return Py_BuildValue("K", 0); CResource* pResource = CResourceManager::Instance().GetResourcePointer(szFileName); @@ -77,7 +77,7 @@ PyObject* grpImageGenerateExpanded(PyObject* poSelf, PyObject* poArgs) if (pImageInstance->IsEmpty()) return Py_BuildException("Cannot load image (filename: %s)", szFileName); - return Py_BuildValue("i", pImageInstance); + return Py_BuildValue("K", pImageInstance); } PyObject* grpImageGenerateFromHandle(PyObject * poSelf, PyObject* poArgs) @@ -89,7 +89,7 @@ PyObject* grpImageGenerateFromHandle(PyObject * poSelf, PyObject* poArgs) CGraphicImageInstance * pImageInstance = CGraphicImageInstance::New(); pImageInstance->SetImagePointer((CGraphicImage *)iHandle); - return Py_BuildValue("i", pImageInstance); + return Py_BuildValue("K", pImageInstance); } PyObject* grpImageDelete(PyObject* poSelf, PyObject* poArgs) diff --git a/src/EterPythonLib/PythonWindowManagerModule.cpp b/src/EterPythonLib/PythonWindowManagerModule.cpp index 4ad219b..ae8dc0c 100644 --- a/src/EterPythonLib/PythonWindowManagerModule.cpp +++ b/src/EterPythonLib/PythonWindowManagerModule.cpp @@ -5,8 +5,8 @@ bool PyTuple_GetWindow(PyObject* poArgs, int pos, UI::CWindow ** ppRetWindow) { - int iHandle; - if (!PyTuple_GetInteger(poArgs, pos, &iHandle)) + unsigned long long iHandle; + if (!PyTuple_GetUnsignedLongLong(poArgs, pos, &iHandle)) return false; if (!iHandle) return false; @@ -53,7 +53,7 @@ PyObject * wndMgrRegister(PyObject * poSelf, PyObject * poArgs) if (!pWindow) return Py_BuildException(); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // SlotWindow @@ -67,7 +67,7 @@ PyObject * wndMgrRegisterSlotWindow(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterSlotWindow(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // GridSlotWindow @@ -81,7 +81,7 @@ PyObject * wndMgrRegisterGridSlotWindow(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterGridSlotWindow(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // TextLine @@ -95,7 +95,7 @@ PyObject * wndMgrRegisterTextLine(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterTextLine(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // MarkBox @@ -109,7 +109,7 @@ PyObject * wndMgrRegisterMarkBox(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterMarkBox(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // ImageBox @@ -123,7 +123,7 @@ PyObject * wndMgrRegisterImageBox(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterImageBox(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // ExpandedImageBox @@ -137,7 +137,7 @@ PyObject * wndMgrRegisterExpandedImageBox(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterExpandedImageBox(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // AniImageBox @@ -151,7 +151,7 @@ PyObject * wndMgrRegisterAniImageBox(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterAniImageBox(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // RegisterButton @@ -165,7 +165,7 @@ PyObject * wndMgrRegisterButton(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterButton(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // RadioButton @@ -179,7 +179,7 @@ PyObject * wndMgrRegisterRadioButton(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterRadioButton(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // ToggleButton @@ -193,7 +193,7 @@ PyObject * wndMgrRegisterToggleButton(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterToggleButton(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // DragButton @@ -207,7 +207,7 @@ PyObject * wndMgrRegisterDragButton(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterDragButton(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // Box @@ -221,7 +221,7 @@ PyObject * wndMgrRegisterBox(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterBox(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // Bar @@ -235,7 +235,7 @@ PyObject * wndMgrRegisterBar(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterBar(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // Line @@ -249,7 +249,7 @@ PyObject * wndMgrRegisterLine(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterLine(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // Slot @@ -263,7 +263,7 @@ PyObject * wndMgrRegisterBar3D(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterBar3D(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } // NumberLine @@ -277,7 +277,7 @@ PyObject * wndMgrRegisterNumberLine(PyObject * poSelf, PyObject * poArgs) return Py_BuildException(); UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterNumberLine(po, szLayer); - return Py_BuildValue("i", pWindow); + return Py_BuildValue("K", pWindow); } ///// Register ///// ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -298,7 +298,7 @@ PyObject * wndMgrIsFocus(PyObject * poSelf, PyObject * poArgs) if (!PyTuple_GetWindow(poArgs, 0, &pWindow)) return Py_BuildException(); - return Py_BuildValue("i", pWindow == UI::CWindowManager::Instance().GetActivateWindow()); + return Py_BuildValue("K", pWindow == UI::CWindowManager::Instance().GetActivateWindow()); } PyObject * wndMgrSetFocus(PyObject * poSelf, PyObject * poArgs) diff --git a/src/ScriptLib/PythonUtils.cpp b/src/ScriptLib/PythonUtils.cpp index 890fd27..cdd7ad5 100644 --- a/src/ScriptLib/PythonUtils.cpp +++ b/src/ScriptLib/PythonUtils.cpp @@ -1,6 +1,9 @@ #include "StdAfx.h" #include "PythonUtils.h" +#define PyLong_AsLong PyLong_AsLongLong +#define PyLong_AsUnsignedLong PyLong_AsUnsignedLongLong + IPythonExceptionSender * g_pkExceptionSender = NULL; bool __PyCallClassMemberFunc_ByCString(PyObject* poClass, const char* c_szFunc, PyObject* poArgs, PyObject** poRet); @@ -71,6 +74,20 @@ bool PyTuple_GetLong(PyObject* poArgs, int pos, long* ret) return true; } +bool PyTuple_GetLongLong(PyObject* poArgs, int pos, long long* ret) +{ + if (pos >= PyTuple_Size(poArgs)) + return false; + + PyObject* poItem = PyTuple_GetItem(poArgs, pos); + + if (!poItem) + return false; + + *ret = PyLong_AsLongLong(poItem); + return true; +} + bool PyTuple_GetDouble(PyObject* poArgs, int pos, double* ret) { if (pos >= PyTuple_Size(poArgs)) @@ -151,6 +168,20 @@ bool PyTuple_GetUnsignedLong(PyObject* poArgs, int pos, unsigned long* ret) return true; } +bool PyTuple_GetUnsignedLongLong(PyObject* poArgs, int pos, unsigned long long* ret) +{ + if (pos >= PyTuple_Size(poArgs)) + return false; + + PyObject* poItem = PyTuple_GetItem(poArgs, pos); + + if (!poItem) + return false; + + *ret = PyLong_AsUnsignedLongLong(poItem); + return true; +} + bool PyTuple_GetUnsignedInteger(PyObject* poArgs, int pos, unsigned int* ret) { if (pos >= PyTuple_Size(poArgs)) diff --git a/src/ScriptLib/PythonUtils.h b/src/ScriptLib/PythonUtils.h index 4055a76..bfdf682 100644 --- a/src/ScriptLib/PythonUtils.h +++ b/src/ScriptLib/PythonUtils.h @@ -9,7 +9,9 @@ bool PyTuple_GetInteger(PyObject* poArgs, int pos, WORD* ret); bool PyTuple_GetByte(PyObject* poArgs, int pos, unsigned char* ret); bool PyTuple_GetUnsignedInteger(PyObject* poArgs, int pos, unsigned int* ret); bool PyTuple_GetLong(PyObject* poArgs, int pos, long* ret); +bool PyTuple_GetLongLong(PyObject* poArgs, int pos, long long* ret); bool PyTuple_GetUnsignedLong(PyObject* poArgs, int pos, unsigned long* ret); +bool PyTuple_GetUnsignedLongLong(PyObject* poArgs, int pos, unsigned long long* ret); bool PyTuple_GetFloat(PyObject* poArgs, int pos, float* ret); bool PyTuple_GetDouble(PyObject* poArgs, int pos, double* ret); bool PyTuple_GetObject(PyObject* poArgs, int pos, PyObject** ret); diff --git a/src/UserInterface/AbstractSingleton.h b/src/UserInterface/AbstractSingleton.h index 7e29e56..57afe08 100644 --- a/src/UserInterface/AbstractSingleton.h +++ b/src/UserInterface/AbstractSingleton.h @@ -9,8 +9,8 @@ public: TAbstractSingleton() { assert(!ms_singleton); - int offset = (int) (T*) 1 - (int) (CSingleton *) (T*) 1; - ms_singleton = (T*) ((int) this + offset); + intptr_t offset = (intptr_t) (T*) 1 - (intptr_t) (CSingleton *) (T*) 1; + ms_singleton = (T*) ((intptr_t) this + offset); } virtual ~TAbstractSingleton()