ActiveX is only supported by IE - the other browsers use a plugin architecture called NPAPI. html
However, there's a cross-browser plugin framework called Firebreath that you might find useful. git
http://stackoverflow.com/questions/7022568/activexobject-in-firefox-or-chrome-not-ie github
可是chrome和firefox均宣布之后再也不支持NPAPI,替代方案是Native Client:https://developer.chrome.com/native-client web
项目地址:https://code.google.com/p/nativeclient/可是NACL目前还不支持IE。 chrome
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 浏览器
Firebreath解决方法:https://groups.google.com/forum/#!topic/firebreath-dev/QzKD_56U07A app
I finally found a solution to make it working ! ide
I tried the axWrapper project but I didn't get to make it working.
I firstly generated and included the .h file by importing the ActiveX type Lib (.tlb) and compiling it in VS (I also got a .c, a .tli and a .tlh file)
I put this in a function:
I have to call this function in a thread be avoid to stuck the web browser (Tested on IE, Firefox, Chrome, Opéra and Safari)
DWORD WINAPI myActiveXInAThread( LPVOID lpParam )
{
// Loading the DLL in prog
HINSTANCE hDLL = LoadLibrary("C:\\PathTo\\myDll.dll");
// Define the pointer type for the function
typedef HRESULT (WINAPI *PAttachControl)(IUnknown*, HWND,IUnknown**);
// Get the function address
PAttachControl ISVR = (PAttachControl) GetProcAddress(hDLL, "MyProcName");
// Init the COM library
CoInitialize(0);
// Pointer to the interface
interfaceName *ptr;
// Create the instance of the Object and the interface
CoCreateInstance(CLSID_ofTheObject,0,CLSCTX_ALL,IID_ofTheInterface,(void**)&ptr);
// Calling a method from dll
ptr->aFunctionFromMyDll();
// Loop Message
MSG Msg;
while( GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage( &Msg );
DispatchMessage( &Msg );
}
// Release the interface
ptr->Release();
// Closing the COM library
CoUninitialize();
// Closing the DLL
FreeLibrary(hDLL);
}
Then I call this next function from JavaScript to launch the ActiveX
std::string MyFbPluginAPI::launchActiveX(){
DWORD dwThreadIdArray;
HANDLE hThreadArray;
hThreadArray = CreateThread(
NULL, // default security attributes
0, // use default stack size
myActiveXInAThread, // thread function name
NULL, // argument to thread function
0, // use default creation flags
&dwThreadIdArray); // returns the thread identifier
return "ActiveX Launched !;
}
youtube视频:https://www.youtube.com/watch?v=am6wA7MSztc 函数
Firebreath浏览器开发指南:http://itindex.net/detail/47019-firebreath-%E6%B5%8F%E8%A7%88%E5%99%A8-%E6%8F%92%E4%BB%B6 工具
http://blog.csdn.net/z6482/article/details/7486921
Firebreath activex DEMO:https://github.com/firebreath/FBAXExample
How is an ActiveX wrapper created with FireBreath?
NPAPI开发详解,Windows版 http://mozilla.com.cn/thread-21666-1-1.html
本文经过多图组合,详细引导初学者开发NPAPI的浏览器插件。
如需测试开发完成的插件请参考http://mozilla.com.cn/kb/dev/A.88/
1. 准备工做
开发工具
本例使用的是visual studio 2008 英文版,下图是关于信息
Windows SDK
本例使用Windows7操做系统 这里下载SDK
NPAPISDK
本例使用的是Firefox4.0.1提供的SDK。
首先,从这里下载mozilla源码。而后,解压firefox-4.0.1.source.tar.bz2文件。
将 \firefox-4.0.1.source\mozilla-2.0\modules\plugin 目录解压缩出来,里面有咱们开发NPAPI插件所需的全部资源。
为了方便你们使用,--这里--提供plugin.rar的下载。
本例将plugin目标解压到D:\code\下(后面统一使用绝对路径,以免异意)
2. 建立Plugin
本着“有图有真相”的原则,下面将连续多图并配文字一步步建立、调试Plugin。图中画红圈的表明须要填写或者须要选择的地方。
建立项目
新建项目
Name项必定要以
np开头,为了未来适应不一样操做系统,最好全小写,不要太长,尽可能控制在8字符内。
本例定义为
npdemo
Location项定义到
plugin\sdk\samples以便项目属性中用相对路径引用NPAPI的SDK
本例定义为
d:\code\plugin\sdk\samples
向导
选择
Application type为
DLL
选择
Empty project
添加文件
首先,添加NPAPI SDK中的Common文件
一共3个文件
而后,添加def文件
命名最好与项目一致
- LIBRARY "npdemo"
-
- EXPORTS
- NP_GetEntryPoints @1
- NP_Initialize @2
- NP_Shutdown @3
复制代码
如今,添加资源
选择
Version
自动生成了
resource.h和
npdemo.rc。因为要在版本信息中加项,因此手工
npdemo.rc
选择“Y”
在图中的BLOCK中添加。注意!
BLOCK 必定要是"
040904e4"
- VALUE "MIMEType", "application/demo-plugin"
复制代码
这里顺便说一下,MIMEType是plugin的惟一标示,须要本身定义
一般的格式是"application/“+ [plugin name]
本例中定义为"application/demo-plugin"
下图是rc文件数据项与plugin数据项(about:plugins 中)的对应关系
下面添加最关键的部分:Plugin实现类
类名能够随便起,本例命名为CPlugin
可是必定要继承自nsPluginInstanceBace
- #pragma once
- #include "pluginbase.h"
-
- class CPlugin : public nsPluginInstanceBase
- {
- private:
- NPP m_pNPInstance;
- NPBool m_bInitialized;
- public:
- CPlugin(NPP pNPInstance);
- ~CPlugin();
-
- NPBool init(NPWindow* pNPWindow) { m_bInitialized = TRUE; return TRUE;}
- void shut() { m_bInitialized = FALSE; }
- NPBool isInitialized() { return m_bInitialized; }
- };
复制代码
- #include "plugin.h"
-
-
- ////// functions /////////
- NPError NS_PluginInitialize()
- {
- return NPERR_NO_ERROR;
- }
-
- void NS_PluginShutdown()
- {
- }
-
- nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
- {
- if(!aCreateDataStruct)
- return NULL;
-
- CPlugin * plugin = new CPlugin(aCreateDataStruct->instance);
- return plugin;
- }
-
- void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
- {
- if(aPlugin)
- delete (CPlugin *)aPlugin;
- }
- ////// CPlugin /////////
- CPlugin::CPlugin(NPP pNPInstance) : nsPluginInstanceBase(),
- m_pNPInstance(pNPInstance),
- m_bInitialized(FALSE)
- {
- }
-
- CPlugin::~CPlugin()
- {
- }
复制代码
修改项目属性
打开项目属性
修改字符集设置为“
Use Multi-Byte Character Set”
添加搜索目录 “
....\include”和“
........\base\public”
添加预编译宏
X86
如今能够编译了!
三、注册、测试
本例编译后,在D:\code\plugin\sdk\samples\npdemo\Debug生成npdemo.dll
打开注册表,在
HKEY_CURRENT_USER\SOFTWARE\MozillaPlugins下新建子项
@mozilla.com.cn/demo
并新建字符串数据“
Path”设值为
D:\code\plugin\sdk\samples\npdemo\Debug\npdemo.dll
打开火狐浏览器 在地址栏输入“about:plugins” 若是在plugin列表中有本例的npdemo.dll及说明咱们的plugin示例已经成功完成
简单的测试页面:
- <HTML>
- <HEAD>
- </HEAD>
- <BODY>
- <embed type="application/demo-plugin">
- </BODY>
- </HTML>
复制代码
特别注意
若是在实际部署中使用安装文件安装plugin,并用注册表的方式注册。那么就
不须要重启火狐
,只要在页面中执行
navigator.plugins.refresh(false);
而后刷新页面便可使用刚安装的plugin