2011-12-14 106 views
2

Backgound步驟基本插件(NPAPI/npruntime)你好世界

    從這裏
  1. 使用Mozilla的代碼:在上述文件中添加的Visual Studio & http://mxr.mozilla.org/seamonkey/source/modules/plugin/tools/sdk/samples/basic/windows/
  2. 新的空項目
  3. 改變Congfiguration類型:動態庫( .dll) 3b。連接器 - >輸入 - >模塊定義文件:BasicPlugin.def
  4. 評論BasicPlugin.cpp,只具備基本功能和DISPLY一個MessageBox爲你好世界
  5. 編譯(全成)&複製到Firefox的插件目錄
  6. 經過約:插件(發現)
  7. 加載HTML調用DLL(失敗)

我想現在使用nPRuntime文件,並作出scriptible插件(不知道如何)。但我不明白爲什麼插件不會被加載。這似乎是所有基本的基礎。任何人都有這個想法?

BasicPlugin.cpp

#include "BasicPlugin.h" 

NPError NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs) 
{ 
MessageBox(NULL,"Hello World","NP_Initialize",MB_OK); 

    // Check the size of the provided structure based on the offset of the last member we need. 
    pFuncs->newp = NPP_New; 
    pFuncs->destroy = NPP_Destroy; 
    pFuncs->setwindow = NPP_SetWindow; 
    pFuncs->newstream = NPP_NewStream; 
    pFuncs->destroystream = NPP_DestroyStream; 
    pFuncs->asfile = NPP_StreamAsFile; 
    pFuncs->writeready = NPP_WriteReady; 
    pFuncs->write = NPP_Write; 
    pFuncs->print = NPP_Print; 
    pFuncs->event = NPP_HandleEvent; 
    pFuncs->urlnotify = NPP_URLNotify; 
    pFuncs->getvalue = NPP_GetValue; 
    pFuncs->setvalue = NPP_SetValue; 

    return NPERR_NO_ERROR; 
} 

//NP_EXPORT(char*) NP_GetPluginVersion() 
//{return PLUGIN_VERSION;} 

//NP_EXPORT(const char*) NP_GetMIMEDescription() 
//{return "application/basic-plugin:bsc:Basic plugin";} 

NPError NP_GetValue(void* future, NPPVariable aVariable, void* aValue) 
{return NPERR_NO_ERROR;} 

NPError OSCALL NP_Shutdown() 
{return NPERR_NO_ERROR;} 

NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved) 
{ 
MessageBox(NULL,"Hello World","NPP_New",MB_OK); 
return NPERR_NO_ERROR; 
} 

NPError NPP_Destroy(NPP instance, NPSavedData** save) 
{return NPERR_NO_ERROR;} 

NPError NPP_SetWindow(NPP instance, NPWindow* window) 
{ 
MessageBox(NULL,"Hello World","NPP_SetWindow",MB_OK); 
return NPERR_NO_ERROR; 
} 

NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype) 
{return NPERR_GENERIC_ERROR;} 

NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) 
{return NPERR_GENERIC_ERROR;} 

int32_t NPP_WriteReady(NPP instance, NPStream* stream) 
{return 0;} 

int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer) 
{return 0;} 

void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) {} 

void NPP_Print(NPP instance, NPPrint* platformPrint) {} 
int16_t NPP_HandleEvent(NPP instance, void* event) 
{return 1;} 

void NPP_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData) {} 

NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) 
{return NPERR_GENERIC_ERROR;} 

NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) 
{return NPERR_GENERIC_ERROR;} 

HTML

<html> 
<body> 
    <center><h1>Basic Plugin Example for Mozilla Test Case</h1></center> 
    This test case is to demonstrate the Basic Plugin example. You should get a message box saying Hello World. 
    <br><br> 
    <center><embed type="application/basic-plugin" border=1 width=600 height=40></center> 
</body> 
</html> 

回答

3

如果你想在Windows上運行這個那麼它將無法正常工作;你有錯誤的windows入口點。你列出的是Linux的入口點。有關FireBreath的windows入口點文件,請參見https://github.com/firebreath/FireBreath/blob/master/src/PluginAuto/Win/np_winmain.cpp;在http://npapi.com/tutorial

編輯還解釋

可以想像可能有很多其他的事情;沒有看到你的整個項目很難推測。它出現在about:插件中,所以你的字符串資源就位。您是否使用.def文件正確導出符號? DllMain會被叫嗎? (不要在那裏使用messagebox,只需記錄一些東西或設置一個斷點)

同樣,FireBreath(除了創建一個NPAPI插件更簡單的方法)創建一個功能完整的npapi插件的示例;你可能會從中看到很多東西。如果沒有這些工作,我就不會在沒有看到你的整個項目的情況下開始猜測;也許作爲github項目或什麼?

+0

因此改變NP_GetEntryPoints的切入點: NPError OSCALL NP_GetEntryPoints(NPPl​​uginFuncs * pFuncs) 和NP_Initialize: NPError FAR PASCAL NP_Initialize(NPNetscapeFuncs * pFuncs)沒有解決它是有別的東西,除了入口點? – hapyfishrmn

+0

我無法設置斷點,VS說沒有任何符號加載。 – hapyfishrmn

+0

那麼解決方案是在VS我沒有將def文件添加到鏈接器。謝謝您的幫助! – hapyfishrmn