问题描述
我正在尝试使用NPAPI作为Firefox的一个测试插件。这是我的代码到目前为止:
I'm trying to do a little test-plugin using NPAPI for firefox. This is my code so far:
/* File: npp_test.cpp
Copyright (c) 2012 by Niklas Rosenstein
Testing the NPAPI interface. */
// - Includes & Preprocessors --------------------------------------------------
// - -------- - ------------- --------------------------------------------------
#define DEBUG
#ifdef DEBUG
# include <iostream>
using namespace std;
# include <windows.h>
#endif // DEBUG
#include <stdint.h>
#include <npapi.h>
#include <npfunctions.h>
#include <npruntime.h>
#define DLLEXPORT extern __declspec(dllexport)
// - NPAPI Calls ---------------------------------------------------------------
// - ----- ----- ---------------------------------------------------------------
NPError NP_New(NPMIMEType pluginType, NPP npp, uint16_t mode, int16_t argc,
char* argn[], char* argv[], NPSavedData* saved);
// - Entrypoints ----------------------
// - ----------- ----------------------
NPError NP_GetEntryPoints(NPPluginFuncs* pFuncs) {
# ifdef DEBUG
cout << "NP_GetEntryPoints\n";
# endif // DEBUG
// Initialize plugin-functions
pFuncs->newp = NP_New;
return NPERR_NO_ERROR;
}
NPError NP_Initialize(NPNetscapeFuncs* npFuncs) {
# ifdef DEBUG
cout << "NP_Initialize\n";
MessageBox(NULL, "NP_Initialize", "Plugin-message", 0);
# endif // DEBUG
return NPERR_NO_ERROR;
}
NPError NP_Shutdown() {
# ifdef DEBUG
cout << "NP_Shutdown\n";
# endif // DEBUG
return NPERR_NO_ERROR;
}
// - Plugin Execution -----------------
// - ------ --------- -----------------
NPError NP_New(NPMIMEType pluginType,
NPP npp,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) {
# ifdef DEBUG
cout << "NP_New\n";
# endif
if (!npp)
return NPERR_INVALID_INSTANCE_ERROR;
return NPERR_NO_ERROR;
}
我正在使用 g ++ 4.4.1
g++ npp_test.cpp -I"D:\include\xulrunner" -shared -Wall -Wextra -o "npp_test.dll"
编译正常,但使用 DLL Expat ,名称不如预期的那样:
Compiles fine, but looking at the DLLs content using DLL Expat, the names are not as expected:
==================================================
Function Name : _get_output_format
Address : 0x6889c658
Relative Address : 0x0001c658
Ordinal : 5 (0x5)
Filename : npp_test.dll
Type : Exported Function
Full Path : C:\Users\niklas\Desktop\npp_test.dll
==================================================
==================================================
Function Name : _Z6NP_NewPcP4_NPPtsPS_S2_P12_NPSavedData
Address : 0x68881270
Relative Address : 0x00001270
Ordinal : 4 (0x4)
Filename : npp_test.dll
Type : Exported Function
Full Path : C:\Users\niklas\Desktop\npp_test.dll
==================================================
==================================================
Function Name : NP_GetEntryPoints@4
Address : 0x688811d8
Relative Address : 0x000011d8
Ordinal : 1 (0x1)
Filename : npp_test.dll
Type : Exported Function
Full Path : C:\Users\niklas\Desktop\npp_test.dll
==================================================
==================================================
Function Name : NP_Initialize@4
Address : 0x68881205
Relative Address : 0x00001205
Ordinal : 2 (0x2)
Filename : npp_test.dll
Type : Exported Function
Full Path : C:\Users\niklas\Desktop\npp_test.dll
==================================================
==================================================
Function Name : NP_Shutdown@0
Address : 0x6888124f
Relative Address : 0x0000124f
Ordinal : 3 (0x3)
Filename : npp_test.dll
Type : Exported Function
Full Path : C:\Users\niklas\Desktop\npp_test.dll
==================================================
不应该像源代码一样被调用?例如,当退出java-dll for firefox时,这些名称是正确的。将 DLLEXPORT 用作
Shouldn't they be called like in the source? When "expating" the java-dll for firefox, just for example, the names are fine. Using DLLEXPORT as
#define DLLEXPORT __declspec(dllexport)
也不起作用。但是至少删除导出的函数 _get_output_format
和 _Z6NP_NewPcP4_NPPtsPS_S2_P12_NPSavedData
/ em>
doesn't work either. But this at least "removes" the functions _get_output_format
and _Z6NP_NewPcP4_NPPtsPS_S2_P12_NPSavedData
from being exported, whyever they are exported when not using DLLEXPORT.
为什么导出的函数名称带有额外的 @ 4
/ @ 0
后缀?我猜这个数字后面的 @
指定函数作为参数的字节数,但是当导出时,实际上不应该包含在名字中, p>
Why are the exported functions names with an additional @4
/@0
suffix ? I guess the number after the @
specifies the number of bytes the function takes as arguments, but when exporting, this actually shouldn't be contained in the name, right ?
推荐答案
@(stack_size_of_params)是stdcall externC函数的名称装饰。我更熟悉Microsoft工具,但我的信念是,您将需要使用.def文件来导出使用stdcall的函数的未装饰名称。
The @(stack_size_of_params) is a name decoration for stdcall extern "C" functions. I'm more familiar with Microsoft tools but my belief is that you will need to use a .def file to export undecorated names for functions that use stdcall.
编辑: Websearch建议 - 用于GNU工具的kill-at命令行选项可以避免使用令人讨厌的.def文件。
Websearch suggests --kill-at command line option for the GNU tools could avoid need for irksome .def files.
这篇关于为什么导出的函数在DLL中没有正确命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!