gpt4 book ai didi

plugins - 基本插件(NPAPI/npruntime) Hello World

转载 作者:行者123 更新时间:2023-12-04 06:04:39 24 4
gpt4 key购买 nike

背景步骤

  • 从这里使用 Mozilla 代码:http://mxr.mozilla.org/seamonkey/source/modules/plugin/tools/sdk/samples/basic/windows/
  • 在 Visual Studio 中新建空项目并添加以上文件
  • 更改的配置类型:动态库 (.dll)
    3b。链接器->输入->模块定义文件:BasicPlugin.def
  • 注释 BasicPlugin.cpp,仅具有基本功能并为 Hello World
  • 显示消息框
  • 编译(成功)并复制到 Firefox Plugins 目录
  • 检查:插件(找到)
  • 加载 HTML 调用 dll(失败)

  • 我现在正在尝试使用 npruntime 文件并制作一个可编写脚本的插件(不确定如何)。但我不明白为什么插件没有加载。这似乎是所有基本的基本。有人对此有想法吗?

    基本插件.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>

    最佳答案

    如果您尝试在 Windows 上运行它,那么它将无法工作;你有错误的 Windows 入口点。您列出的那些是 linux 的入口点。见 https://github.com/firebreath/FireBreath/blob/master/src/PluginAuto/Win/np_winmain.cpp对于 FireBreath 的 windows 入口点文件;在 http://npapi.com/tutorial 中也有解释

    编辑

    假设还有很多其他的东西;没有看到你的整个项目很难推测。它显示在 about:plugins 中,因此您的字符串资源已经到位。您是否使用 .def 文件正确导出符号? DllMain 是否被调用? (不要在那里使用消息框,只需记录一些内容或设置断点)

    同样,FireBreath 是(除了作为创建 NPAPI 插件的更简单方法之外)创建功能齐全的 npapi 插件的示例;你可能会从中学到很多东西。如果没有看到你的整个项目,我就无法开始推测。也许作为一个 github 项目或什么?

    关于plugins - 基本插件(NPAPI/npruntime) Hello World ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8507670/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com