1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
HRESULT reponse;
TCOMITestServeurCOMT<TTestServeurCOM> serveur;
std::cout<< "Initialize: " << std::endl;
if(!SUCCEEDED(reponse=CoInitialize(NULL)))
switch(reponse){
case S_OK:
std::cout << "The COM library was initialized successfully on this thread." << std::endl;
break;
case S_FALSE:
std::cout << "The COM library is already initialized on this thread.." << std::endl;
break;
case RPC_E_CHANGED_MODE:
std::cout << "A previous call to CoInitializeEx specified the concurrency model for this thread as multithread apartment (MTA). If running Windows 2000, this could also mean that a change from neutral-threaded apartment to single-threaded apartment occurred." << std::endl;
break;
default:
std::cout << "Reponse inconnue???: 0x" << std::hex << reponse << std::endl;
break;
}
else
std::cout << "The COM library was initialized successfully on this thread." << std::endl;
std::cout << std::endl << "CoCreateInstanceEx: " << std::endl;
// Création de la structure MULTI_QI
MULTI_QI multiQiRes;
multiQiRes.pIID = &IID_ITestServeurCOM, //& IID_IUnknown;
multiQiRes.pItf = NULL;
multiQiRes.hr = 0;
//Creation du COSERVERINFO
COSERVERINFO serveurInfo;
wchar_t serveurName[] = L"UC06P1556.fr.pierre-fabre.lcl";
serveurInfo.pwszName = serveurName;
serveurInfo.pAuthInfo = NULL;
serveurInfo.dwReserved1 = 0;
serveurInfo.dwReserved2 = 0;
reponse=CoCreateInstanceEx(CLSID_TTestServeurCOM, NULL, CLSCTX_REMOTE_SERVER, &serveurInfo, 1, &multiQiRes);
//CLSCTX_REMOTE_SERVER|CLSCTX_LOCAL_SERVER
if(!SUCCEEDED(reponse))
switch(reponse){
case REGDB_E_CLASSNOTREG:
std::cout << "A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt." << std::endl;
break;
case E_NOINTERFACE:
std::cout << "None of the interfaces requested in the pResults array were successfully retrieved." << std::endl;
break;
case CLASS_E_NOAGGREGATION:
std::cout << "This class cannot be created as part of an aggregate." << std::endl;
break;
case CO_S_NOTALLINTERFACES:
std::cout << "At least one, but not all of the interfaces requested in the pResults array were successfully retrieved. The hr field of each of the MULTI_QI structures in pResults indicates with S_OK or E_NOINTERFACE whether the specific interface was returned." << std::endl;
break;
default:
std::cout << "Reponse inconnue???: 0x" << std::hex << reponse << std::endl;
break;
}
else{
std::cout << "Location and connection to the specified class object was successful." << std::endl;
serveur = static_cast< ITestServeurCOM * >(multiQiRes.pItf);
}
if( SUCCEEDED(reponse) ){
std::cout << std::endl << "Appel de l'objet distant:" << std::endl;
std::wcout << "Nombre de processeurs: " << serveur.Nombre << " et voila." << std::endl;
}
system("PAUSE"); |