-1

深くお詫び申し上げます。ファイルが正しいディレクトリにコピーされなかったため、読み取ることができませんでした。結局、拡張機能はすべての Windows プラットフォームで機能します。これは、常に適切なエラー処理を実行することを思い出させるものです。

率直な質問: FireBreath が生成した .dll ファイル (適切な .js、.html、および .json が必要であることは明らかです) 以外のファイルを、Chrome 拡張機能内の FireBreath プラグインにアップロードする必要がありますか?

全体像: FireBreath は .dll を生成します。この .dll ファイルを、chrome://extensions/ unpacked を使用してアップロードした Chrome 拡張フォルダーにロードするだけで十分だと思います。つまり、追加の C++ コードをアップロードする必要はないと思います。plugin.openUserIdFromFile()を呼び出すと、エラーが発生します。

成功: NPAPI FireBreath プラグインを使用して、デスクトップ ユーザー名をファイルから Chrome 拡張機能に読み込みました。プラグインが開発された Windows デスクトップで動作します。

失敗: NPObject のメソッドの呼び出し中にエラーが発生しました。すべての Windows 環境 (開発環境以外の XP、7、または 8) でエラーが発生します。

既知:友人がhttp://www.dependencywalker.com/ソフトウェアを実行したところ、彼の環境では IEShims.dll が欠落している依存関係であることがわかりました。

JavaScript Chrome 拡張機能が FireBreath プラグイン dll を呼び出します。

$(document).ready(function () {
    setInterval(getAllChromeTabs, 10000);

    var plugin = document.getElementById("pluginId");

    while (user.length < 1) {
        user = plugin.openUserIdFromFile();
    }
    console.log(user);
});

Chrome 拡張機能から呼び出される C++ FireBreath プラグイン関数:

std::string LabStatsPluginAPI::openUserIdFromFile()
{
    std::string aTempFileName = "aTempFileName";

    DWORD nBufferLength = MAX_PATH;
    LPTSTR lpBuffer = (new TCHAR[nBufferLength]);
    DWORD tempPath = GetTempPath(nBufferLength, lpBuffer);

    char* localTempPathArray = new char[nBufferLength];
    for (int i = 0; i < nBufferLength; i++) {
        localTempPathArray[i] = (char)lpBuffer[i];
    }
    std::string localTempPath(localTempPathArray);
    localTempPath = localTempPath + aTempFileName;

    std::ifstream streamFromFile;
    std::ifstream::pos_type fileSize;
    streamFromFile.open( localTempPath, std::ios::in|std::ios::binary|std::ios::ate );

    char* userNameString;
    int userNamesize = streamFromFile.tellg();
    streamFromFile.seekg(0, std::ios::beg);
    userNameString = new char[userNamesize];
    streamFromFile.read(userNameString, userNamesize);

    delete[] lpBuffer;
    delete[] localTempPathArray;

    std::string userNameSafeString(userNameString);
    delete[] userNameString;

    return userNameSafeString;
}
4

1 に答える 1

0

次の C++ への変更 (if ステートメントの挿入) により、関数が修正されます。

char* userNameString;
int userNamesize = streamFromFile.tellg();
if (userNamesize < 1) {
    return ""; // no file found
}

streamFromFile.seekg(0, std::ios::beg);
userNameString = new char[userNamesize];
streamFromFile.read(userNameString, userNamesize);
于 2013-05-01T23:02:09.337 に答える