call_in_appdomain, fonction
Exécute une fonction dans un domaine d’application spécifié.
Syntaxe
template <typename ArgType1, ...typename ArgTypeN>
void call_in_appdomain(
DWORD appdomainId,
void (*voidFunc)(ArgType1, ...ArgTypeN) [ ,
ArgType1 arg1,
...
ArgTypeN argN ]
);
template <typename RetType, typename ArgType1, ...typename ArgTypeN>
RetType call_in_appdomain(
DWORD appdomainId,
RetType (*nonvoidFunc)(ArgType1, ...ArgTypeN) [ ,
ArgType1 arg1,
...
ArgTypeN argN ]
);
Paramètres
appdomainId
Domaine d’application dans lequel appeler la fonction.
voidFunc
Pointeur vers une void
fonction qui prend N paramètres (0 <= N <= 15).
nonvoidFunc
Pointeur vers une fonction quivoid
prend N paramètres (0 <= N <= 15).
arg1... argN
Zéro à 15 paramètres à passer à voidFunc
ou nonvoidFunc
dans l’autre domaine d’application.
Valeur de retour
Résultat de l’exécution voidFunc
ou nonvoidFunc
dans le domaine d’application spécifié.
Notes
Les arguments de la fonction passée call_in_appdomain
ne doivent pas être des types CLR.
Exemple
// msl_call_in_appdomain.cpp
// compile with: /clr
// Defines two functions: one takes a parameter and returns nothing,
// the other takes no parameters and returns an int. Calls both
// functions in the default appdomain and in a newly-created
// application domain using call_in_appdomain.
#include <msclr\appdomain.h>
using namespace System;
using namespace msclr;
void PrintCurrentDomainName( char* format )
{
String^ s = gcnew String(format);
Console::WriteLine( s, AppDomain::CurrentDomain->FriendlyName );
}
int GetDomainId()
{
return AppDomain::CurrentDomain->Id;
}
int main()
{
AppDomain^ appDomain1 = AppDomain::CreateDomain( "First Domain" );
call_in_appdomain( AppDomain::CurrentDomain->Id,
&PrintCurrentDomainName,
(char*)"default appdomain: {0}" );
call_in_appdomain( appDomain1->Id,
&PrintCurrentDomainName,
(char*)"in appDomain1: {0}" );
int id;
id = call_in_appdomain( AppDomain::CurrentDomain->Id, &GetDomainId );
Console::WriteLine( "default appdomain id = {0}", id );
id = call_in_appdomain( appDomain1->Id, &GetDomainId );
Console::WriteLine( "appDomain1 id = {0}", id );
}
Sortie
default appdomain: msl_call_in_appdomain.exe
in appDomain1: First Domain
default appdomain id = 1
appDomain1 id = 2
Spécifications
Fichier d’en-tête<msclr\appdomain.h>
Espace de noms msclr
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour