From e9e6be9ff273bff7ff8cb2b13c2e41b3b693106f Mon Sep 17 00:00:00 2001 From: rnv Date: Thu, 27 Sep 2018 14:25:21 +0300 Subject: [PATCH] Some corrections related to using UNICODE. --- src/CAM/CAM_Application.cxx | 9 ++++++--- src/GLViewer/GLViewer_BaseObjects.cxx | 6 +++++- src/GLViewer/GLViewer_Viewer2d.cxx | 16 ++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 00da56461..247270583 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -320,14 +320,17 @@ CAM_Module* CAM_Application::loadModule( const QString& modName, const bool show GET_VERSION_FUNC getVersion = 0; #ifdef WIN32 - #ifdef UNICODE LPTSTR str_libname = new TCHAR[libName.length() + 1]; str_libname[libName.toWCharArray(str_libname)] = '\0'; -#else - LPTSTR str_libname = libName.toLatin1().constData(); +#else + QByteArray arr = libName.toLatin1(); + LPTSTR str_libname = arr.constData(); #endif HINSTANCE modLib = ::LoadLibrary( str_libname ); +#ifdef UNICODE + delete str_libname; +#endif if ( !modLib ) { LPVOID lpMsgBuf; diff --git a/src/GLViewer/GLViewer_BaseObjects.cxx b/src/GLViewer/GLViewer_BaseObjects.cxx index 6e65422f2..e1193a538 100644 --- a/src/GLViewer/GLViewer_BaseObjects.cxx +++ b/src/GLViewer/GLViewer_BaseObjects.cxx @@ -1469,9 +1469,13 @@ bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerC LPTSTR str = new TCHAR[aText.length() + 1]; str[aText.toWCharArray(str)] = '\0'; #else - LPTSTR str = aText.toLatin1().constData(); + QByteArray arr = FileName.toLatin1(); + LPTSTR str = arr.constData(); #endif TextOut( dc, x, y, str, aText.length() ); +#ifdef UNICODE + delete str; +#endif SelectObject ( dc, old1 ); SelectObject ( dc, old2 ); diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index b11c4d710..62963722b 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -794,15 +794,19 @@ bool GLViewer_Viewer2d::translateTo( VectorFileType aType, QString FileName, Pap HDC bitDC = CreateCompatibleDC ( screen_dc ); //The context compatible with screen #ifdef UNICODE - LPTSTR str = new TCHAR[FileName.length() + 1]; - str[FileName.toWCharArray(str)] = '\0'; - LPTSTR empty = L""; + LPTSTR str = new TCHAR[FileName.length() + 1]; + str[FileName.toWCharArray(str)] = '\0'; + LPTSTR empty = L""; #else - LPTSTR str = FileName.toLatin1().constData(); - LPTSTR empty = ""; + QByteArray arr = FileName.toLatin1(); + LPTSTR str = arr.constData(); + LPTSTR empty = ""; #endif hMetaFileDC = CreateEnhMetaFile( bitDC, str, &r, empty ); +#ifdef UNICODE + delete str; +#endif SetMapMode( hMetaFileDC, MM_HIMETRIC ); SetWindowOrgEx( hMetaFileDC, 0, r.bottom, NULL ); HRGN ClipRgn = CreateRectRgn( 0, 0, AW, AH ); @@ -817,7 +821,7 @@ bool GLViewer_Viewer2d::translateTo( VectorFileType aType, QString FileName, Pap ReleaseDC( 0, screen_dc ); DeleteDC( bitDC ); - aCurVP->getGLWidget()->translateBackgroundToEMF( hMetaFileDC, &aViewerCS, &aPaperCS ); + aCurVP->getGLWidget()->translateBackgroundToEMF( hMetaFileDC, &aViewerCS, &aPaperCS ); } #endif -- 2.39.2