Hi,
I try to retun any type of value from an C++ XPCOM component.
// Javascript
var value = Test()
^ varlue can be of any type (string, array, etc...)
I've successfully make it work in Javascript with the fallowing code
(based on the Mozilla XML-RPC extension) :
http://lxr.mozilla.org/mozilla1.7/source/extensions/xml-rpc/src/nsXmlRpcClient.js#342
/* Create an instance of the given ContractID, with given interface */
function createInstance(contractId, intf) {
return
Components.classes[contractId].createInstance(Components.interfaces[intf])
}
/* return type */
function testReturn(type) {
const SUPPORTSID = '@mozilla.org/supports-';
var ret
switch(type) {
case 'INT32':
ret = createInstance(SUPPORTSID + 'PRInt32;1',
'nsISupportsPRInt32')
ret.data = 65
break
case 'STRING':
ret = createInstance(SUPPORTSID + 'cstring;1',
'nsISupportsCString')
ret.data = 'arf'
break
case 'DOUBLE':
ret = createInstance(SUPPORTSID + 'double;1',
'nsISupportsDouble')
ret.data = 2.4
break
....
}
return ret;
}
But I can't make It working in C++ :
XPIDL prototype of my method :
nsISupports Test();
The C++ implementation :
NS_IMETHODIMP
nsDBusImpl::TestSupports(nsISupports **_retval) {
nsresult rv;
nsCOMPtr ret =
do_CreateInstance([EMAIL PROTECTED]/supports-PRInt32;1″, &rv);
if (NS_FAILED(rv)) {
return rv;
}
ret->SetData(42);
// _retval = (nsISupports **) &ret; // Does not work
// *_retval = ret; // Segfault
return NS_OK;
}
Who can I return *any* can of object from an method?
Best Regards,
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom