Changeset 75


Ignore:
Timestamp:
Jul 9, 2009, 8:37:15 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: OS/2: Implemented QLibrary.

Location:
trunk/src/corelib/plugin
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/plugin/plugin.pri

    r2 r75  
    2020}
    2121
     22
     23
     24
     25
    2226unix {
    2327        SOURCES += plugin/qlibrary_unix.cpp
  • trunk/src/corelib/plugin/qlibrary_os2.cpp

    r63 r75  
    1 /****************************************************************************
     1/***************************************************************************
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    44** Contact: Qt Software Information ([email protected])
     5
     6
    57**
    68** This file is part of the QtCore module of the Qt Toolkit.
     
    4749#include "qdir.h"
    4850
    49 #if defined(QT_NO_LIBRARY) && defined(Q_OS_WIN)
    50 #undef QT_NO_LIBRARY
    51 #pragma message("QT_NO_LIBRARY is not supported on Windows")
    52 #endif
    53 
    54 #include "qt_windows.h"
     51#ifndef QT_NO_LIBRARY
    5552
    5653QT_BEGIN_NAMESPACE
    5754
    58 extern QString qt_error_string(int code);
     55// provide human readable strings for common OS/2 DOS errors
     56// @todo make exported if needed anywhere else
     57static QString qt_os2_error_string(APIRET code)
     58{
     59    // see qt_error_string()
     60
     61    const char *s = 0;
     62    QString ret;
     63
     64    switch (code) {
     65        case NO_ERROR:
     66            return ret;
     67        case ERROR_FILE_NOT_FOUND:
     68            s = QT_TRANSLATE_NOOP("QIODevice", "File not found");
     69            break;
     70        case ERROR_PATH_NOT_FOUND:
     71            s = QT_TRANSLATE_NOOP("QIODevice", "Path not found");
     72            break;
     73        case ERROR_TOO_MANY_OPEN_FILES:
     74            return qt_error_string(EMFILE);
     75        case ERROR_ACCESS_DENIED:
     76            s = QT_TRANSLATE_NOOP("QIODevice", "Access denied");
     77            break;
     78        case ERROR_SHARING_VIOLATION:
     79            s = QT_TRANSLATE_NOOP("QIODevice", "Sharing violation");
     80            break;
     81        default:
     82            break;
     83    }
     84
     85    if (s)
     86        // ######## this breaks moc build currently
     87//         ret = QCoreApplication::translate("QIODevice", s);
     88        ret = QString::fromLatin1(s);
     89    else
     90        // ######## this breaks moc build currently
     91//         ret = QString(QCoreApplication::translate("QIODevice","System error %1")).arg(code);
     92        ret = QString::fromLatin1("System error %1").arg(code);
     93    return ret;
     94}
    5995
    6096bool QLibraryPrivate::load_sys()
    6197{
    62 #ifdef Q_OS_WINCE
    63     QString attempt = QFileInfo(fileName).absoluteFilePath();
    64 #else
    65     QString attempt = fileName;
    66 #endif
     98    pHnd = 0;
    6799
    68     //avoid 'Bad Image' message box
    69     UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
    70     QT_WA({
    71         pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(attempt).utf16());
    72     } , {
    73         pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(attempt)).data());
    74     });
    75    
    76     if (pluginState != IsAPlugin) {
    77 #if defined(Q_OS_WINCE)
    78         if (!pHnd && ::GetLastError() == ERROR_MOD_NOT_FOUND) {
    79             QString secondAttempt = fileName;
    80             QT_WA({
    81                 pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(secondAttempt).utf16());
    82             } , {
    83                 pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(secondAttempt)).data());
    84             });
    85         }
    86 #endif
    87         if (!pHnd && ::GetLastError() == ERROR_MOD_NOT_FOUND) {
    88             attempt += QLatin1String(".dll");
    89             QT_WA({
    90                 pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(attempt).utf16());
    91             } , {
    92                 pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(attempt)).data());
    93             });
    94         }
     100    QByteArray attempt = QFile::encodeName(QDir::toNativeSeparators(fileName));
     101
     102    APIRET rc;
     103    char errModule[CCHMAXPATH] = { '\0' };
     104    rc = DosLoadModule(errModule, sizeof(errModule), attempt, &pHnd);
     105    if (rc == ERROR_FILE_NOT_FOUND) {
     106        attempt += ".DLL";
     107        rc = DosLoadModule(errModule, sizeof(errModule), attempt, &pHnd);
    95108    }
    96109
    97     SetErrorMode(oldmode);
    98     if (!pHnd) {
    99         errorString = QLibrary::tr("Cannot load library %1: %2").arg(fileName).arg(qt_error_string());
     110    if (rc != NO_ERROR) {
     111        errorString = QLibrary::tr("Cannot load library %1: %2")
     112            .arg(fileName).arg(qt_os2_error_string(rc));
     113        if (*errModule != '\0')
     114            errorString += QLibrary::tr(" (failed module: %1)").arg(errModule);
     115        return false;
    100116    }
    101     if (pHnd) {
    102         errorString.clear();
    103         QT_WA({
    104             TCHAR buffer[MAX_PATH + 1];
    105             ::GetModuleFileNameW(pHnd, buffer, MAX_PATH);
    106             attempt = QString::fromUtf16(reinterpret_cast<const ushort *>(&buffer));
    107         }, {
    108             char buffer[MAX_PATH + 1];
    109             ::GetModuleFileNameA(pHnd, buffer, MAX_PATH);
    110             attempt = QString::fromLocal8Bit(buffer);
    111         });
    112         const QDir dir =  QFileInfo(fileName).dir();
    113         const QString realfilename = attempt.mid(attempt.lastIndexOf(QLatin1Char('\\')) + 1);
    114         if (dir.path() == QLatin1String("."))
    115             qualifiedFileName = realfilename;
    116         else
    117             qualifiedFileName = dir.filePath(realfilename);
    118     }
    119     return (pHnd != 0);
     117
     118    errorString.clear();
     119    rc = DosQueryModuleName(pHnd, sizeof(errModule), errModule);
     120    Q_ASSERT(rc == NO_ERROR);
     121
     122    qualifiedFileName = QDir::fromNativeSeparators(QFile::decodeName(QByteArray(errModule)));
     123
     124    return true;
    120125}
    121126
    122127bool QLibraryPrivate::unload_sys()
    123128{
    124     if (!FreeLibrary(pHnd)) {
    125         errorString = QLibrary::tr("Cannot unload library %1: %2").arg(fileName).arg(qt_error_string());
     129    APIRET rc = DosFreeModule(pHnd);
     130    if (rc != NO_ERROR) {
     131        errorString = QLibrary::tr("Cannot unload library %1: %2").arg(fileName).arg(qt_os2_error_string(rc));
    126132        return false;
    127133    }
     
    132138void* QLibraryPrivate::resolve_sys(const char* symbol)
    133139{
    134 #ifdef Q_OS_WINCE
    135     void* address = (void*)GetProcAddress(pHnd, (const wchar_t*)QString::fromLatin1(symbol).utf16());
    136 #else
    137     void* address = (void*)GetProcAddress(pHnd, symbol);
    138 #endif
    139     if (!address) {
     140    void *address = 0;
     141    APIRET rc = DosQueryProcAddr(pHnd, 0, symbol, (PFN*) &address);
     142    if (rc != NO_ERROR) {
    140143        errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
    141             QString::fromAscii(symbol)).arg(fileName).arg(qt_error_string());
     144            QString::fromAscii(symbol)).arg(fileName).arg(qt_));
    142145    } else {
    143146        errorString.clear();
     
    146149}
    147150QT_END_NAMESPACE
     151
     152
  • trunk/src/corelib/plugin/qlibrary_p.h

    r2 r75  
    5454//
    5555
    56 #ifdef Q_WS_WIN
     56#if
    5757# include "QtCore/qt_windows.h"
     58
     59
    5860#endif
    5961#include "QtCore/qlibrary.h"
     
    7375public:
    7476
    75 #ifdef Q_WS_WIN
     77#if
    7678    HINSTANCE
     79
     80
    7781#else
    7882    void *
Note: See TracChangeset for help on using the changeset viewer.