0

問題は次のとおりです。ライブラリを動的にロードし、このライブラリから 1 つの関数を実行する Qt アプリケーションがあります (コード例を参照)。

...
QLibrary library( "d:/Libs/MyLib.dll" );
if ( !library.load( ) )
    qDebug( ) << library.errorString( );
if ( library.load( ) )
    qDebug( ) << "library loaded";

typedef void ( *StartPrototype ) ( );
StartPrototype Start = ( StartPrototype ) library.resolve( "Start" );
if ( !Start )
{
    qDebug() << "Start( ) failed!";
}

Start();
...

また、読み込まれた dll からの Start( ) 関数の定義は次のようになります。

extern "C" __declspec( dllexport ) void Start( )
{
    ofstream myfile( "example.txt" );
    if ( myfile.is_open( ) )
    {
        myfile << "This is a line.\n";
        myfile.close( );
    }
}

Qt アプリケーションはd:/Projects/MyApp.exeにあり、実行するとexample.txtがd:/Projects/example.txtに表示されます ( MyApp.exeの現在の作業ディレクトリとして)

しかし、 example.txtを dll と同じディレクトリ ( d:/Libs/example.txt )に保存したいと考えています。パスを直接指定せずにそれを行うことはできますか? ロードされたライブラリとその中のすべての関数の作業ディレクトリを指定する方法はありますか? dll パスを dll 関数 (ファイルの作成など) の現在の作業ディレクトリとして設定する方法。ありがとう。

4

0 に答える 0