once a nativescript plugin is loaded from script怎么解决

Creating a C++ XPCOM component
This is a step-by-step tutorial on creating, building and registering an
component on Linux and MS Windows.
The complete source code for this tutorial can be downloaded from .
Download the Gecko SDK for your platform.
You can find it at .
You can choose a different Mozilla release if you like.
Extract the SDK to a local directory.
for your main interface.
On Windows you can use the guidgen utility.
On Linux you can use the uuidgen utility.
Create the
file - IMyComponent.idl
Use the following template, add methods and attributes to the interface.
Fill in the GUID you have generated.
#include "nsISupports.idl"
[scriptable, uuid(_YOUR_INTERFACE_GUID_)]
interface IMyComponent : nsISupports
long Add(in long a, in long b);
Generate the interface header and typelib files out of the interface definition file.
utility that comes with Gecko SDK.
Substitute the "_DIR_" in the following commands with the full path to the xpcom/idl directory found under your Gecko SDK main directory.
xpidl -m header -I_DIR_ IMyComponent.idl will create the IMyComponent.h header file.
xpidl -m typelib -I_DIR_ IMyComponent.idl will create the IMyComponent.xpt typelib file.
The interface header file IMyComponent.h contains templates for building your component header and implementation files. You can copy and paste the templates to create these files, changing only your component name.
Create your component header file - MyComponent.h.
Start by inserting double inclusion protection code (#ifndef _MY_COMPONENT_H_ ....).
Add #include "IMyComponent.h" to include the interface definition.
Create a GUID for your component.
Add the following lines, which define your component name, contract ID, and GUID:
#define MY_COMPONENT_CONTRACTID "@/XPCOMSample/MyC1"
#define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"
#define MY_COMPONENT_CID _YOUR_COMPONENT_GUID_
Copy the header template from IMyComponent.h (starting with /* Header file */) into the MyComponent.h file.
Replace all the instances of _MYCLASS_ with the name of your component.
Create your component implementation file - MyComponent.cpp.
Add #include "MyComponent.h" to include your component definitions.
Copy the implementation template from IMyComponent.h (starting with /* Implementation file */) into the MyComponent.cpp file.
Replace all the instances of _MYCLASS_ with the name of your component.
Add method implementation code.
Create your module definitions file - MyComponentModule.cpp.
Add #include "nsIGenericFactory.h" to include Mozilla GenericFactory definitions.
Add #include "MyComponent.h" to include your component definitions.
Add NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent) to define the constructor for your component.
static nsModuleComponentInfo components[] =
MY_COMPONENT_CLASSNAME,
MY_COMPONENT_CID,
MY_COMPONENT_CONTRACTID,
MyComponentConstructor,
to define the class name, contract ID and GUID of your component.
Add NS_IMPL_NSGETMODULE("MyComponentsModule", components) to export the above information to Mozilla.
Create the makefiles and/or projects.
You can use the templates provided with this sample to create your custom makefile.
Alternatively, you can create a Visual C++ project with similar settings (on Windows).
Download the sample code from .
Extract the sample to a local directory.
Edit the makefile.
The makefile is located in the src directory of the sample.
It is named Makefile for Linux, MyComponent.mak for Windows
Edit the makefile, changing the GECKO_SDK_PATH variable to point to your Gecko SDK directory.
Added: When using the included Visual Studio project:
Open the project settings: Project & Settings...
Choose Settings For: All Configurations in the upper left corner.
Open the C/C++ tab and choose Preprocessor in the Category drop-down list.
Make sure that "Additional include directories" points to your Gecko SDK.
Open the Link tab and choose Input in the Category drop-down list.
Make sure that the "Additional library path" points to your Gecko SDK.
Build the sample.
Open a command shell (cmd on W tcsh, bash, xterm etc. on Linux).
Navigate to the sample src directory.
On Linux issue a make command. MyComponent.so file is created.
On Windows issue a nmake /f MyComponent.mak command. Debug\MyComponent.dll is created.
Alternatively, on Windows, issue a nmake /f "MyComponent.mak" CFG="MyComponent - Win32 Release" command for a release build. Release\MyComponent.dll is created.
Added: When using the included Visual Studio project:
Select the wanted configuration (Debug/Release) in Build & Set Active Configuration...
Choose Build & Build MyComponent.dll
Register the new component with Mozilla.
Copy MyComponent.so/MyComponent.dll and IMyComponent.xpt file to the Mozilla components directory.
On Windows this directory is typically located at:
C:\Program Files\Mozilla Firefox\components.
On Linux this directory is typically located at ~/firefox/components (or ~/mozilla/components).
Run the regxpcom command supplied with the Gecko SDK to register the new component.
You might need to provide an additional parameter:
regxpcom -x _COMPONENTS_DIR_ where _COMPONENTS_DIR_ is the components directory.
Delete the xpti.dat and compreg.dat files from your Mozilla profile directory.
These files will be automatically rebuilt by Mozilla the next time it is restarted.
Added: Alternatively you can "touch" (either create or update) a file called .autoreg in the main Mozilla/Firefox installation directory.
The profile directory is typically located at:
~/.mozilla/firefox/default.??? on Linux.
C:\Documents and Settings\USERNAME\Application Data\Mozilla\Firefox\Profiles\default.??? on Windows.
Test the new component.
Restart Mozilla.
Open the MyComponentTest.html file provided with the sample and click the "Go" button.
If everything is OK you should see a dialog saying "3 + 4 = 7".
IBM developerWorks - XPCOM Overview
by Doug Turner.
[chapter 8 - ]
June 3, 2005
Modified the Windows makefile (MyComponent.mak) to work with the latest Gecko SDK. The old version of the sample can be found .
Added Visual Studio 6 project file to the sample.
Added a tip about using the ".autoreg" file for registering new components.
Comments closedvar HelloPlugin = { callNativeFunction: function (success, fail, resultType) { return Cordova.exec( success, fail, &com.tricedesigns.HelloPlugin&, &nativeFunction&, [resultType]);
#import &Cordova/CDV.h&@interface HelloPlugin : CDVPlugin- (void) nativeFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)@end
#import &HelloPlugin.h&@implementation HelloPlugin- (void) nativeFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { //get the callback id NSString
*callbackId = [arguments pop]; NSLog(@&Hello, this is a native function called from PhoneGap/Cordova!&); NSString *resultType = [arguments objectAtIndex:0]; CDVPluginResult * if ( [resultType isEqualToString:@&success&] ) { result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsString: @&Success :)&]; [self writeJavascript:[result toSuccessCallbackString:callbackId]]; } else { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @&Error :(&]; [self writeJavascript:[result
toErrorCallbackString:callbackId]]; }}@end
&script type=&text/javascript& charset=&utf-8& src=&HelloPlugin.js&&&/script&
function callNativePlugin( returnSuccess ) { HelloPlugin.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess );} function nativePluginResultHandler
(result) { alert(&SUCCESS: \r\n&+result );}function nativePluginErrorHandler (error) { alert(&ERROR: \r\n&+error );}
&body onload=&onBodyLoad()&& &h1&Hey, it's Cordova!&/h1& &button onclick=&callNativePlugin('success');&&Click to invoke the Native Plugin with an SUCCESS!&/button& &button
onclick=&callNativePlugin('error');&&Click to invoke the Native Plugin with an ERROR!&/button&&/body&
Great tutorial, this would have saved a lot of time for me it was available a bit earlier - I just published Bonjour plugin for PhoneGap/Cordova few days ago ().
Looks like the Cordova is a bit shaky target at the moment, since 1.6 seems to require to use lowercase &cordova& variable for native access.
Really, Great tutorial ! Thank you !
This is great but could you update the download to be compatible with version 1.6?
Demo application state support for plugins...this is vital and can cause issues in the main app functionality.
I'm seeing fairly large differences between the setup for 1.x.x. and Phonegap 2.0.&&So many that I suggest you change the title to indicate 1.x.x.x support only.&&While not outright misinformation, this procedure is an expensive time sink for anyone trying
to create a plugin with the 2.0 Cordova.
Thanks for the article. I am finding that Cordova.exec (and cordova.exec) is undefined. I am using version 1.9. The cordova ready event has fired. I am wondering if I am missing something obvious. Thanks for any help.
Your explain is very careful that give me lots of help,Can you tell us this app how to kick off,that will be perfect,thank u!
Can you tell us the flow of kick off in&&app,that will be perfect,thanks advance!
HI again....Just to answer my own question (see a couple messages above)....
I found my original prognosis was not correct. I did find, for some odd reason, I needed to change the javascript line that calls cordova.exec to:
Cordova.exec( success, fail,&&
&&&&&&&&&&&&&&&&&&&& &com.tricedesigns.HelloPlugin&,&&
&&&&&&&&&&&&&&&&&&&& &nativeFunction&,&&
&&&&&&&&&&&&&&&&&&&& [resultType]);
Notice, I removed the &return& in the line.
to post a comment.
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:8405次
排名:千里之外
转载:23篇
(2)(2)(10)(9)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 native maven plugin 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信