Partager via


Chargement des données de caractère et d’animation

[Microsoft Agent est déconseillé à partir de Windows 7 et peut être indisponible dans les versions ultérieures de Windows.]

Une fois que vous avez un pointeur vers l’interface IAgentEx, vous pouvez utiliser la méthode Load pour charger un personnage et récupérer son interface IAgentCharacterEx. Il existe trois possibilités différentes pour le chemin de chargement d’un caractère. Le premier est compatible avec Microsoft Agent 1.5 où le chemin spécifié est le chemin complet et le nom de fichier d’un fichier caractère. La deuxième possibilité est de spécifier le nom de fichier uniquement, auquel cas, Agent recherche dans son répertoire Chars. La dernière possibilité consiste à fournir un paramètre Variant vide qui entraîne le chargement du caractère par défaut.

   // Create a variant to store the filename of the character to load

   const LPWSTR kpwszCharacter = L"merlin.acs";

   VariantInit(&vPath);

   vPath.vt = VT_BSTR;
   vPath.bstrVal = SysAllocString(kpwszCharacter);

   // Load the character

   hRes = pAgentEx->Load(vPath, &lCharID, &lRequestID);

   // Get its IAgentCharacterEx interface

   hRes = pAgentEx->GetCharacterEx(lCharID, &pCharacterEx);

Vous pouvez utiliser cette interface pour accéder aux méthodes du caractère :

   // Show the character.  The first parameter tells Microsoft
   // Agent to show the character by playing an animation.

   hRes = pCharacterEx->Show(FALSE, &lRequestID);

   // Make the character speak

   bszSpeak = SysAllocString(L"Hello World!");

   hRes = pCharacterEx->Speak(bszSpeak, NULL, &lRequestID);

   SysFreeString(bszSpeak);

Lorsque vous n’avez plus besoin de services Microsoft Agent, par exemple lorsque votre application cliente s’arrête, relâchez ses interfaces. Notez que la libération de l’interface de caractères ne décharge pas le caractère. Appelez la méthode Unload pour effectuer cette opération avant de libérer l’interface IAgentEx :

// Clean up

if (pCharacterEx) {

   // Release the character interface

   pCharacterEx->Release();

   // Unload the character.  NOTE:  releasing the character
   // interface does NOT make the character go away.  You must
   // call Unload.

   pAgentEx->Unload(lCharID);
}
   
// Release the Agent

pAgentEx->Release();

VariantClear(&vPath);