Hello,
I am pretty new to XPCOM, but I really enjoy working with it. However, I now
am facing problems that I am unable to solve. I got an interface that
returns an array of other interface pointers:
void parse( in string fname, out unsigned long count, [retval, array,
size_is(count)]out nsIPlaylistEntry result );
The component implementing the interface, is written in Python and it just
returns Python list as a result of the call:
def parse(self):
try:
# open XML file
f = open(self.fname, "r")
# create content handler and set it in expat
p = make_parser()
dh = content_handler()
p.setContentHandler()
# parse the XML
# white parsing, it will fill a list of Python classes that are
derived from nsIEntry interface
p.parse(f)
# and return the list of entries (dh.entries is Python's list)
# and every entry in the list is Python class that implements
appropriate interface
# but is not a component.
return dh.entries
catch Exception, error:
raise ServerException, nsError.NS_ERROR_FAILURE
Now when I am trying to call this method from my C++ program, it is getting
really confusing:
nsresult rv;
nsCOMPtr<nsIParamXMLParser> parser(do_CreateEntry(XML_PARSER_CONTRACT_ID,
&rv);
if ( NS_SUCCEEDED(rv) ) {
// parse the file and get the results
PRUint32 count;
nsIEntry **array; // I am using raw pointer because I do not know how to
use nsCOMPtr<> here
rv = parser->parse(fname.c_str(), &count, &array);
if ( NS_SUCCEEDED(rv) ) {
// here we should get the array with interface pointers
// !!!
}
}
Now at the line with !!!, I have several problems. First, I do not know what
is the right way to call AddRef on the interfaces that are returned to me in
the array (getter_AddRefs<>() is not going to work with an array). I am
getting a valid pointer to an array of pointers (I can see the instances of
Python stubs in the debugger), but every time when I am trying to call
anythings except AddRef() on these pointers, the program crashes somewhere
in xpcom.dll.
Please if you ever were in this or simular situation, let me know what am I
doing wrong and how I can modify my program to make it work. Oh, I have
forgotten one thing - I am using standalong xpcom, not mozilla.
Thanks a lot in advance.