HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
{
    QStringList searchOrder;

#if !defined(QT_BOOTSTRAPPED)
    if (!onlySystemDirectory)
        searchOrder << QFileInfo(qAppFileName()).path();
#endif
    searchOrder << qSystemDirectory();

    if (!onlySystemDirectory) {
        const QString PATH = QString::fromWCharArray((const wchar_t *)_wgetenv(L"PATH"));
        searchOrder << PATH.split(QLatin1Char(';'), QString::SkipEmptyParts);
    }

    const QString fileName = QString::fromWCharArray(libraryName) + QLatin1String(".dll");
    // Start looking in the order specified
    for (int i = 0; i < searchOrder.count(); ++i) {
        QString fullPathAttempt = searchOrder.at(i);
        if (!fullPathAttempt.endsWith(QLatin1Char('\\')))
            fullPathAttempt.append(QLatin1Char('\\'));
        fullPathAttempt.append(fileName);
        HINSTANCE inst = ::LoadLibrary((const wchar_t *)fullPathAttempt.utf16());
        if (inst != 0)
            return inst;
    }

    return 0;
}
Example #2
0
static HINSTANCE
load(const wchar_t *libraryName,
     bool onlySystemDirectory = true)
{
    QStringList searchOrder;

#if !defined(QT_BOOTSTRAPPED)
    if (!onlySystemDirectory) {
        searchOrder << QFileInfo( QCoreApplication::applicationFilePath() ).path();
    }
#endif
    searchOrder << qSystemDirectory();

    if (!onlySystemDirectory) {
        const QString PATH( QLatin1String( qgetenv("PATH").constData() ) );
#     ifdef __NATRON_WIN32__
        const QChar pathSep = QChar::fromLatin1(';');
#     else
        // This code is windows-only anyway, but this is here for consistency with other parts of the source
        const QChar pathSep = QChar::fromLatin1(':');
#     endif
        searchOrder << PATH.split(pathSep, QString::SkipEmptyParts);
    }
    QString fileName = QString::fromWCharArray(libraryName);
    fileName.append( QLatin1String(".dll") );

    // Start looking in the order specified
    Q_FOREACH(const QString &path, searchOrder) {
        QString fullPathAttempt = path;

        if ( !fullPathAttempt.endsWith( QLatin1Char('\\') ) ) {
            fullPathAttempt.append( QLatin1Char('\\') );
        }
        fullPathAttempt.append(fileName);

        std::wstring ws = fullPathAttempt.toStdWString();
        HINSTANCE inst = ::LoadLibraryW( ws.c_str() );

        if (inst != 0) {
            return inst;
        }
    }