Le type void, dans le fichier IDL, n'est utilisé que comme paramètre de retour. Pour siginifer qu'une fonction n'a pas de paramètre d'entrée, mettre une liste de paramètre vide '()'.
Ceci est incorrect :
void F( void );
Ceci est correct :
void F();
Et a pour équivalent C++ :
NS_IMETHODIMP myclass::F( void )
(Tiré de http://www.mozilla.org/scriptable/faq.html#i9)
Lorsque l'on désire implémenter une fonction semblable à ceci (.idl):
interface nsIXPCTestString : nsISupports {
string GetStringA();
};
il ne faut pas l'implémenter de la manière suivante (.cpp):
NS_IMETHODIMP xpcstringtest::GetStringA(char **_retval) { *_retval = "result of xpcstringtest::GetStringA"; return NS_OK; }
mais de la manière suivante (.cpp):
NS_IMETHODIMP xpcstringtest::GetStringA(char **_retval) { const char myResult[] = "result of xpcstringtest::GetStringA"; if(!_retval) return NS_ERROR_NULL_POINTER; *_retval = (char*) nsMemory::Clone(myResult, sizeof(char)*(strlen(myResult)+1)); return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; }
A priori, cela est également valable pour les chaînes de caractères passé comme paramètre 'out'.
Beaucoup de méthodes requièrent un nsEmbedString. Poour convertir un const char *, en nsEmbedString, utiliser NS_LITERAL_STRING. Exemple :
nsEmbedString String = NS_LITERAL_STRING( "texte à convertir." );
(Tiré de http://www.mozilla.org/scriptable/xpidl/idl-authors-guide/rules.html#types)
| IDL | C++ mapping |
|---|---|
void1) | void |
boolean | PRBool |
octet | PRUint8 |
short | PRInt16 |
long | PRInt32 |
long long | PRInt64 |
unsigned short | PRUint16 |
unsigned long | PRUint32 |
unsigned long long | PRUint64 |
float | float |
double | double |
char | char |
wchar | PRUnichar |
string | char* |
wstring | PRUnichar* |
void en début de page