26 #include <QtCore/QBool>
27 #include <QtCore/QTextCodec>
34 #include <QtCore/QDir>
35 #include <QtCore/QString>
36 #include <QtCore/QLibrary>
48 #ifndef _USE_OLD_IOSTREAMS
52 #if defined(__MINGW32__)
53 # define WIN32_CAST_CHAR (const WCHAR*)
55 # define WIN32_CAST_CHAR (LPCWSTR)
63 #ifdef KDELIBS_STATIC_LIBS
64 static bool kde4prefixInitialized =
false;
90 Q_ASSERT(pos < MAX_PATH + 1);
100 if (kde4prefixInitialized)
103 QDir kde4prefixDir(QString::fromUtf16((ushort*) STATIC_INSTALL_PATH));
104 if (kde4prefixDir.exists()){
107 kde4prefixInitialized =
true;
115 retval = QDir::fromNativeSeparators(retval);
118 kde4prefixInitialized =
true;
128 #ifndef KDELIBS_STATIC_LIBS
135 BOOL WINAPI
DllMain ( HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
137 BOOL WINAPI
DllMain ( HANDLE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
140 switch ( fdwReason ) {
141 case DLL_PROCESS_ATTACH:
146 case DLL_PROCESS_DETACH:
158 if( lpReserved == NULL )
187 if ( subKey.isEmpty() )
194 if ( ERROR_SUCCESS!=RegOpenKeyExW ( key,
WIN32_CAST_CHAR subKey.utf16(), 0, KEY_READ, &hKey ) )
197 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey,
WIN32_CAST_CHAR item.utf16(), NULL, NULL, NULL, &dwSize ) )
200 lszValue =
new TCHAR[dwSize];
202 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey,
WIN32_CAST_CHAR item.utf16(), NULL, &dwType, ( LPBYTE ) lszValue, &dwSize ) ) {
206 RegCloseKey ( hKey );
208 QString res = QString::fromUtf16 ( (
const ushort* ) lszValue );
220 QString path_ = QDir::convertSeparators ( QFileInfo ( fileName ).absoluteFilePath() );
223 SHELLEXECUTEINFOW execInfo;
225 SHELLEXECUTEINFO execInfo;
227 memset ( &execInfo,0,
sizeof ( execInfo ) );
228 execInfo.cbSize =
sizeof ( execInfo );
230 execInfo.fMask = SEE_MASK_INVOKEIDLIST | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
232 execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
234 const QString verb ( QLatin1String (
"properties" ) );
238 return ShellExecuteExW ( &execInfo );
240 return ShellExecuteEx ( &execInfo );
252 QLatin1String(
"Control Panel\\International"),
253 QLatin1String(
"Locale"), &ok );
257 QLatin1String(
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout\\DosKeybCodes"),
261 return localeName.toLatin1();
270 QLatin1String(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"),
280 char *buf =
new char[BUFSIZE];
283 strlcpy(buf,
"Debug:",BUFSIZE);
284 strlcat(buf,msg,BUFSIZE);
287 strlcpy(buf,
"Warning:",BUFSIZE);
288 strlcat(buf,msg,BUFSIZE);
291 strlcpy(buf,
"Critical:",BUFSIZE);
292 strlcat(buf,msg,BUFSIZE);
295 strlcpy(buf,
"Fatal:",BUFSIZE);
296 strlcat(buf,msg,BUFSIZE);
300 strlcat(buf,
"\n",BUFSIZE);
301 OutputDebugStringW( (WCHAR*)QString::fromLatin1(buf).utf16());
312 fprintf(stderr,
"Debug: %s\n", msg);
315 fprintf(stderr,
"Warning: %s\n", msg);
318 fprintf(stderr,
"Critical: %s\n", msg);
321 fprintf(stderr,
"Fatal: %s\n", msg);
341 if(GetLastError() == ERROR_ACCESS_DENIED)
361 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_INPUT_HANDLE),_O_TEXT);
363 hf = _fdopen( hCrt,
"r" );
365 i = setvbuf( stdin, NULL, _IONBF, 0 );
368 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
370 hf = _fdopen( hCrt,
"w" );
372 i = setvbuf( stdout, NULL, _IONBF, 0 );
375 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_ERROR_HANDLE),_O_TEXT);
377 hf = _fdopen( hCrt,
"w" );
379 i = setvbuf( stderr, NULL, _IONBF, 0 );
383 ios::sync_with_stdio();
392 class debug_streambuf:
public std::streambuf
395 debug_streambuf(
const char *
prefix)
398 index = rindex = strlen(buf);
402 virtual int overflow(
int c = EOF)
406 char cc = traits_type::to_char_type(c);
412 OutputDebugStringW((WCHAR*)QString::fromLatin1(buf).utf16());
416 return traits_type::not_eof(c);
431 return IMAGE_SUBSYSTEM_WINDOWS_CE_GUI;
438 PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)GetModuleHandle(NULL);
439 PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS) ((
char *)dosHeader + dosHeader->e_lfanew);
440 if (ntHeader->Signature != 0x00004550)
442 subSystem = IMAGE_SUBSYSTEM_UNKNOWN;
445 subSystem = ntHeader->OptionalHeader.Subsystem;
478 static class kMessageOutputInstaller {
480 kMessageOutputInstaller() : stdoutBuffer(
"stdout:"), stderrBuffer(
"stderr:"), oldStdoutBuffer(0), oldStderrBuffer(0)
482 if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
493 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
494 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
497 else if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
506 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
507 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
510 }
else if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI) {
513 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
514 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
517 qWarning(
"unknown subsystem %d detected, could not setup qt message handler",
subSystem());
519 ~kMessageOutputInstaller()
522 std::cout.rdbuf(oldStdoutBuffer);
524 std::cerr.rdbuf(oldStderrBuffer);
528 debug_streambuf stdoutBuffer;
529 debug_streambuf stderrBuffer;
530 std::streambuf* oldStdoutBuffer;
531 std::streambuf* oldStderrBuffer;
538 return ( file.endsWith( QLatin1String(
".exe" ) ) ||
539 file.endsWith( QLatin1String(
".com" ) ) ||
540 file.endsWith( QLatin1String(
".bat" ) ) ||
541 file.endsWith( QLatin1String(
".sln" ) ) ||
542 file.endsWith( QLatin1String(
".lnk" ) ) );
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
The dll entry point - get the instance handle for GetModuleFleNameW Maybe also some special initializ...
void initKde4prefixUtf16()
static QString * kde4Prefix
bool isExecutable(const QString &file)
static int subSystem()
retrieve type of win32 subsystem from the executable header
static HINSTANCE kdecoreDllInstance
static void redirectToConsole()
redirect stdout, stderr and cout, wcout, cin, wcin, wcerr, cerr, wclog and clog to console ...
static bool attachConsoleResolved
BOOL(WINAPI * attachConsolePtr)(DWORD dwProcessId)
try to attach to the parents console
static void kMessageOutputDebugString(QtMsgType type, const char *msg)
kde and qt debug message printer using windows debug message port
QString getWin32ShellFoldersPath(const QString &folder)
Windows-specific functions needed in kdecore.
static class kMessageOutputInstaller kMessageOutputInstallerInstance
typedef BOOL(WINAPI *PtrTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION lpTimeZoneInformation
static bool attachToConsole()
QByteArray getWin32LocaleName()
static wchar_t kde4prefixUtf16[MAX_PATH+2]
static void kMessageOutputFileIO(QtMsgType type, const char *msg)
kde and qt debug message printer using FILE pointer based output
bool showWin32FilePropertyDialog(const QString &fileName)
Shows native MS Windows file property dialog for a file fileName.
static attachConsolePtr attachConsole
QString getWin32RegistryValue(HKEY key, const QString &subKey, const QString &item, bool *ok)