Partager via


Tableaux conformes

La taille d’un tableau conforme peut varier ou se conformer chaque fois que le client le transmet à une procédure distante sur le serveur. La définition d’interface dans le fichier MIDL de l’application permet au client de spécifier la taille du tableau chaque fois qu’il appelle la procédure distante. Utilisez des crochets vides ([ ]) ou un astérisque entre crochets ([*]) dans la définition du tableau pour indiquer un tableau conforme.

L’exemple suivant contient la définition d’une procédure distante dans une interface dans un fichier MIDL. Le client spécifie la taille du tableau qu’il transmet au serveur par le paramètre arraySize.

[
    /*Attributes are defined here. */
]
interface MyInterface
{
    MyRemoteProc(
         long lArraySize,
         [size_is(lArraySize)] char achArray[*]
    );

    /* Other interface procedures are defined here. */
}

La définition d’interface utilise l’attribut MIDL [size_is] pour spécifier la taille du tableau que le client transmet au serveur. Si vous préférez indiquer la valeur maximale des numéros d’index du tableau, utilisez plutôt l’attribut [max_is]. Pour plus d’informations sur ces attributs MIDL, consultez Attributs de tableau.

Le fragment de code suivant illustre comment un client peut appeler la procédure distante définie dans le fichier MIDL précédent.

long lArrayLength = 20;
char achCharArray[20], achAnotherCharArray[200];

// Code to store 20 chars in achCharArray goes here.

MyRemoteProc(
    lArrayLength ,
    achCharArray);

lArrayLength = 200;

// Code to store 200 chars in achAnotherCharArray goes here.

MyRemoteProc(
    lArrayLength ,
    achAnotherCharArray);

Ce fragment appelle la procédure distante MyRemoteProc deux fois. Lors du premier appel, il transmet un tableau de 20 éléments. Lors du deuxième appel, le client transmet un tableau de 200 éléments.