call_in_appdomain 函式
指定應用程式定義域中執行的函式。
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 ]
);
參數
appdomainId
用來呼叫函式的 appdomain。voidFunc
指標void n 參數的函式 (0 < = N < = 15)。nonvoidFunc
指標為非-void n 參數的函式 (0 < = N < = 15)。arg1...argN
0 到 15 個參數傳遞至voidFunc或nonvoidFunc中其他的 appdomain。
傳回值
執行的結果voidFunc或nonvoidFunc在指定的應用程式定義域中。
備註
函式的引數傳遞至call_in_appdomain不能 CLR 型別。
範例
// 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 );
}
Output
default appdomain: msl_call_in_appdomain.exe
in appDomain1: First Domain
default appdomain id = 1
appDomain1 id = 2
需求
標頭檔 <msclr\appdomain.h>
Namespace msclr