다음을 통해 공유


type_to_xmit 함수

스텁은 type_to_xmit 함수를 호출하여 애플리케이션에서 제공하는 형식을 전송된 형식으로 변환합니다. 함수는 다음과 같이 정의됩니다.

void __RPC_USER <type>_to_xmit ( 
     <type> __RPC_FAR *, <xmit_type> __RPC_FAR *     __RPC_FAR *);

첫 번째 매개 변수는 애플리케이션 데이터에 대한 포인터입니다. 두 번째 매개 변수는 함수가 전송된 데이터를 가리키도록 설정됩니다. 함수는 전송된 형식에 대한 메모리를 할당해야 합니다.

다음 예제에서 클라이언트는 DOUBLE_LINK_TYPE 형식의 [in, out] 매개 변수가 있는 원격 프로시저를 호출합니다. 클라이언트 스텁은 DOUBLE_LINK_TYPE_to_xmit 명명된 type_to_xmit 함수를 호출하여 이중 연결된 목록 데이터를 크기가 큰 배열로 변환합니다.

함수는 목록의 요소 수를 결정하고, 해당 요소를 저장할 수 있을 만큼 큰 배열을 할당한 다음, 목록 요소를 배열에 복사합니다. 함수가 반환되기 전에 두 번째 매개 변수 인 ppArray가 새로 할당된 데이터 구조를 가리키도록 설정됩니다.

void __RPC_USER DOUBLE_LINK_TYPE_to_xmit ( 
    DOUBLE_LINK_TYPE __RPC_FAR * pList, 
    DOUBLE_XMIT_TYPE __RPC_FAR * __RPC_FAR * ppArray)
{
    short cCount = 0;
    DOUBLE_LINK_TYPE * pHead = pList;  // save pointer to start 
    DOUBLE_XMIT_TYPE * pArray;
 
    /* count the number of elements to allocate memory */
    for (; pList != NULL; pList = pList->pNext)
        cCount++;
 
    /* allocate the memory for the array */
    pArray = (DOUBLE_XMIT_TYPE *) MIDL_user_allocate 
         (sizeof(DOUBLE_XMIT_TYPE) + (cCount * sizeof(short)));
    pArray->sSize = cCount;
 
    /* copy the linked list contents into the array */
    cCount = 0;
    for (i = 0, pList = pHead; pList != NULL; pList = pList->pNext)
        pArray->asNumber[cCount++] = pList->sNumber;
 
    /* return the address of the pointer to the array */
    *ppArray = pArray;
}