// nsIComponentManager
exports.getPointerForInterface = (obj, iid) => {
return components.manager.getPointerForInterface(obj, iid)
}
xul.js:
'use strict'
const { Cc, Ci } = require('chrome')
exports.types = require('./types.js')
const {
ctypes,
EnumType,
default_abi,
uint32_t
} = exports.types
exports.nsISupports = ctypes.voidptr_t
const xul = ctypes.open('xul.dll')
exports.nsresult = ctypes.uint32_t
exports.NSLocationType = EnumType([
// 'NS_APP_LOCATION', For bolt 38, doesn't have this yet
'NS_EXTENSION_LOCATION',
'NS_SKIN_LOCATION',
'NS_BOOTSTRAPPED_LOCATION'
], uint32_t)
/*
* XRE_API(nsresult,
* XRE_AddManifestLocation, (NSLocationType aType,
* nsIFile* aLocation))
*/
exports.XRE_AddManifestLocation = xul.declare('XRE_AddManifestLocation',
default_abi, exports.nsresult,
exports.NSLocationType.type, // NSLocationType aType
exports.nsISupports // nsIFile aLocation
)
/*
*
* XRE_API(nsresult,
* XRE_AddJarManifestLocation, (NSLocationType aType,
* nsIFile* aLocation))
*/
exports.XRE_AddJarManifestLocation =
xul.declare('XRE_AddJarManifestLocation', default_abi, exports.nsresult,
exports.NSLocationType.type, // NSLocationType aType
exports.nsISupports // nsIFile aLocation
)
exports.MozFile = (path) => {
let file = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsILocalFile)
file.initWithPath(path)
return file.QueryInterface(Ci.nsILocalFile)
}
const appFile = xul.MozFile(path.join(AppInfo.appCodePath,
'chrome.manifest'))
const appFilePtr = getPointerForInterface(appFile, Ci.nsIFile)
const appFileCtypePointer =
xul.types.voidptr_t(xul.types.UInt64(appFilePtr))
xul.XRE_AddManifestLocation(xul.NSLocationType.NS_EXTENSION_LOCATION,
appFileCtypePointer)
在 2015/12/24 00:27, Cameron Kaiser <ckai...@floodgap.com> 写道:
On 12/23/15 8:09 AM, 罗勇刚(Yonggang Luo) wrote:
>No, js-ctypes does not have any support for calling methods on C++
>classes. In fact, that functionality was WONTFIXed a while back:
>https://bugzilla.mozilla.org/show_bug.cgi?id=505907.
OK, I've done it with my own patch, indeed, I just want to calling
C APIs
with
XPCOM pointers. So I implemented the following function to deal
with my
situation:
[...]
+ /**
+ * getPointerForInterface
+ *
+ * Returns string representation of the pointer for a
instance of the
interface
+ *
+ * @param aInstance - The instance of the interface
+ * @param aIID - IID of interface requested
+ * @return ACString in hex format with "0x" prepended, or
empty if the
instance have no aIID
+ */
+ ACString getPointerForInterface(in nsISupports aInstance,
+ in nsIIDRef aIID);
Interesting. How does your code work in practice?
Cameron Kaiser
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform
- Send from WPS Mail -
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform