這邊紀錄的是自己在瀏覽了網路上的參考文件後,
compile npruntime時所做的紀錄

先附上所參考的文件: mozilla firefox 插件開發快速入門  NPAPI開發詳解  Compiling The npruntime Sample Plugin in Visual Studio

1. 安裝所需的開發環境(後面附上我所使用的版本,供參考)
    Gecko SDK (1.9.1)
    Visual Studio C++ 2010 Express
    Firefox (13.0)

2. 下載npruntime範例程式


以下是參考我前面所附上的文件,依據自己的環境所做的一些修改紀錄

1. 建立新的專案
    File -> New -> Project -> Visual C++ -> Win32 -> Win32 Project
    在Name的欄位輸入nprt -> OK  // 名稱一定要是np開頭
    在Application Settings選擇DLL 並設定為 Empty Project

2. 將範例程式加入專案中
    在nprt上按右鍵Add -> Existing Item,將範例程式的所有檔案都選進來
    // Header Files存放.h檔,Resource Files存放.rc檔,Source Files存放.cpp檔和.def檔
    // Makefile和.html檔會放在nprt資料夾下

3. 將剛剛下載的Gecko SDK解壓縮,放在C:\xulrunner-sdk

4. 設定include path
    在nprt上按右鍵Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories
    "C:\xulrunner-sdk\sdk\include";"C:\xulrunner-sdk\include\plugin";"C:\xulrunner-sdk\include\nspr";"C:\xulrunner-sdk\include\java"

5.  在nprt上按右鍵Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
     WIN32;_WINDOWS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE;XP_WIN;_X86_;NPSIMPLE_EXPORTS; _DEBUG 
     // 保留原本的,新增以上這些

6.  在nprt上按右鍵Properties -> Configuration Properties -> C/C++ -> Precompiled Headers -> Precompiled Header 
     選擇Not Using Precompiled Headers

7.  在nprt上按右鍵Properties -> Configuration Properties -> Linker -> Input -> Module Difition File
     輸入nprt.def


完成以上,就可以開始編譯,但是此時會出現很多error
以下附上我所遇到的error以及解決的方法

error C2146: syntax error : missing ';' before identifier 'handleEvent'
=> 將int16換成int16_t 
// 要將所有的int16和int32皆換成int16_t及int32_t

fatal error C1083: Cannot open include file: 'npupp.h': No such file or directory
// 將#include "npupp.h"換成#include "npfunctions.h"

error C3861: 'printf': identifier not found
// 加上#include <stdio.h>

error C2065: 'PR_TRUE' : undeclared identifier
// 將所有的PR_TRUE和PR_FALSE換成true及false

error C2039: 'utf8characters' : is not a member of '_NPString'
// 將所有的utf8characters和utf8Length用UTF8Characters和UTF8Length取代

error C2664: 'DrawTextW' : cannot convert parameter 2 from 'char [128]' to 'LPCWSTR' 
// DrawText 換成 DrawTextA

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
// 加上 #ifdef INCLUDE_JAVA (in npapi.h)
           #include "jri.h" /* Java Runtime Interface */
           #else
           #define jref void *
           #define JRIEnv void
           #endif
// 參考 npapi.h

fatal error RC1015: cannot open include file 'afxres.h'
// 參考 Visual Studio Express Notes
// 解壓縮winres.zip,將afxres.h和winres.h加入header files中

順利編譯完成後,會在Debug資料夾下產生nprt.dll檔
可以直接把nprt.dll放入firefox的plugins目錄底下(若沒有此目錄可自己自建 C:\Program Files\Mozilla Firefox\plugins) 

也可以利用註冊的方式載入dll檔:
執行 -> 輸入regedit, 會開啟註冊表 -> 在HKEY_LOCAL_MACHINE\SOFTWARE\MozillaPlugins下新增機碼@mozilla.com.cn/demo -> 按右鍵新增字串值數據: Path 值:(dll檔的絕對路徑)

開啟firefox在網址列輸入about:plugins,可以搜尋列表中是否有剛剛創建的dll檔以確認是否上傳成功。 

arrow
arrow
    全站熱搜

    RxoRwp 發表在 痞客邦 留言(0) 人氣()