From 5d867d77a5d38f024eca63ab9a470e64be66df53 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 18 Aug 2016 18:28:57 +0100 Subject: Fix bug (and compiler error) on Windows - wchar username support --- singleapplication.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/singleapplication.cpp b/singleapplication.cpp index 6b3b85b..4fba93c 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -68,12 +68,13 @@ void SingleApplicationPrivate::genBlockServerName( int timeout ) // User level block requires a user specific data in the hash if( options & SingleApplication::Mode::User ) { #ifdef Q_OS_WIN - char username[UNLEN + 1]; + wchar_t username [ UNLEN + 1 ]; // Specifies size of the buffer on input - DWORD usernameLength = sizeof( username ); + DWORD usernameLength = UNLEN + 1; if( GetUserName( username, &usernameLength ) ) { - // usernameLength includes the null terminating character - appData.addData( username, usernameLength - 1 ); + char buffer[512]; + size_t length = wcstombs( buffer, username, 512 ); + appData.addData( buffer, length ); } else { appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() ); } -- cgit v1.2.1