Application of Outdated NPAPI Technology.
Implemented using NPAPI simulated Flash technology, encapsulating NAPI for FF/Chrome and ActiveX for IE.
| Table of contents | illustrate | Remark |
|---|---|---|
| mozilla | Firefox organization code, open source SDK | Please do not modify |
| npapi | NPAPI SDK | Please do not modify |
| npplugin | Implementation of NPAPI plug-in | Automatic interface processing and data redirection have been implemented, and can be used without modification by default. |
| regs | Registry operations, including 32-bit/64-bit, and related security processing | Users generate a private CLSID based on the program and modify the corresponding ID value |
| flashness | FlashNess plugin implementation code | Users generate corresponding business codes, CLSIDs and other information according to their needs, and the interface implementation reference examples |
| release | Compile and generate directory to protect the generated npFlashNess.dll and registration batch, test page, etc. | Users can register and open test.html for simple test |
Project creation
Use the Visual Studio wizard to create an active template library (using ATL) as a starting point to start writing a dynamic link library (DLL).
Document description
| file name | illustrate | Remark |
|---|---|---|
| FlashNess.vcxproj | The vs wizard generates the main project file of the vc++ project, including the version information of VC++, as well as information on the platform, configuration and project functions. | |
| FlashNess.vcxproj.filters | The project filter file generated by the wizard contains the filter and corresponding file information. | |
| FlashNess.idl | The IDL definitions of the type library, interface and component classes defined by the project are processed by the MIDL compiler to generate C++ interface definitions and GUID declarations (FlashNess.h), GUID definitions (FlashNess_i.c), type library (FlashNess.tlb), and marshalling codes (FlashNess_p.c and dlldata.c) | Project core file, interface definition |
| FlashNess.h | Contains the C++ interface definition and GUID declaration of the project defined in FlashNess.idl, regenerated by MIDL during compilation. | No need to modify it, it will be automatically generated after modifying the idl file. |
| FlashNess.cpp | Interface implementation containing object mapping and DLL export | Core functions and business logic implementation |
| FlashNess.rc | Program resource list | You can modify it in the Explorer, try not to modify it manually to avoid errors |
| FlashNess.def | The definition file provides information provided by the linker about the DLL's required export, such as wanting to export a certain interface for direct external calls. | There is basically no need to modify the plug-in. Just export DllGetClassObject, DllCanUnloadNow, DllRegisterServer, DllUnregisterServer, DllInstall |
| stdAfx.h/cpp | Precompiled files | No modification required, the basic library is already included |
| resource.h | Define such as button ID, image ID, etc. | No modification required |
Interface implementation
NPAPI analysis
How to develop a new NPAPI and ActiveX-based plug-in system using the demo as above?
Code pull
git clone https://github.com/walklang/FlashNess.git
Create a new ATL interface using the wizard
Search for COM components for details and create a new interface
NPAPI interface extension (optional)
FlashNess has simulated interface calls that are compatible with NPAPI and ActiveX. Searching for ActiveX to add interface functions can quickly realize the compatible implementation of IE and FF/chrome browsers.
Introduction to new examples of interfaces
FlashNess implements Get interface and Set interface methods, and other forms can be used to refer to implementation; users can search for IDL format and implementation methods by themselves. It should be noted that if it is a Get interface (such as ReadData), then the function name during implementation needs to be added to get_ (such as get_ReadData). Users can implement it through the following two file references.
Open the FlashNess.idl file and add new functions to the IFlashNess interface
interface IFlashNess : IDispatch{
[id(1)] HRESULT WriteData([in] BSTR bstrPath);
[propget, id(2)] HRESULT ReadShort([out, retval] SHORT* pVal);
[propget, id(3)] HRESULT ReadData([out, retval] BSTR* data);
};
Open the FlashNess.h file and add a new interface to the end of the file.
STDMETHOD(WriteData)(BSTR bstrPath) {
if (bstrPath == nullptr) return S_FALSE;
ATL::CComBSTR bstr_val = bstrPath;
data_ = bstr_val;
return S_OK;
}
STDMETHOD(get_ReadShort)(SHORT* pVal){
*pVal = 1;
return S_OK;
}
STDMETHOD(get_ReadData)(BSTR* pVal) {
if (!pVal) return S_FALSE;
std::string temp = CT2AEX<>(data_.c_str());
CComBSTR value(temp.c_str());
*pVal = value.Detach();
return S_OK;
}
std::wstring data_;