Just for the record, this is the way I managed to populate the array
with native types:

nsCOMPtr<nsIMutableArray> myMutableArray =
do_CreateInstance(NS_ARRAY_CONTRACTID);

// C strings
        char *cstrTest = "anything";
        nsCOMPtr<nsISupportsCString> strArg;
        argStr = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
        NS_ENSURE_TRUE(strArg, NS_ERROR_FAILURE);
        argStr->SetData( nsCString(cstrTest) );
        rv = myMutableArray->AppendElement(strArg, PR_FALSE);
        NS_ENSURE_SUCCESS(rv, rv);

// Int16 (short)

        PRInt16 iNum = 0;
        nsCOMPtr<nsISupportsPRInt16> shortArg;
        shortArg = do_CreateInstance(NS_SUPPORTS_PRINT16_CONTRACTID, &rv);
        NS_ENSURE_TRUE(shortArg, NS_ERROR_FAILURE);
        shortArg->SetData(iNum);
        rv = myMutableArray->AppendElement(shortArg, PR_FALSE);
        NS_ENSURE_SUCCESS(rv, rv);


If somebody knows a less convoluted way of achieve the same, please
let me know

Mark


On Aug 7, 5:03 pm, Mark <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to use a MutableArray in a XPCOM, but I noticed I have no
> idea how to add new elements of primitive types such as string (char
> *) and short (PRInt16). I cannot find any code that shows how to do
> this. I tried something like:
>
> nsCOMPtr<nsIMutableArray> myarray =
> do_CreateInstance(NS_ARRAY_CONTRACTID);
>
> char *elem = "hi";
> nsCOMPtr<nsISupportsString> arg =
> do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
> NS_ENSURE_TRUE(arg, NS_ERROR_FAILURE);
>
> arg->SetData(elem);
>
> rv = myarray->AppendElement(arg, PR_FALSE);
>
> I got this error:
>
> error: no matching function for call to
> 'nsDerivedSafe<nsISupportsString>::SetData(char*&)
>
> Besides, even if I get this to compile, the initializations of so
> many
> nsISupportsString or nsISupportsPRUint16 will be overkill
>
> Any help will be greatly appreciated
>
> Thanks,
>
> Mark


_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to