NetApiBufferAllocate 함수(lmapibuf.h)

NetApiBufferAllocate 함수는 힙에서 메모리를 할당합니다. NetApiBufferFree 함수와의 호환성이 필요한 경우에만 이 함수를 사용합니다. 그렇지 않으면 메모리 관리 함수를 사용합니다.

구문

NET_API_STATUS NET_API_FUNCTION NetApiBufferAllocate(
  [in]  DWORD  ByteCount,
  [out] LPVOID *Buffer
);

매개 변수

[in] ByteCount

할당할 바이트 수입니다.

[out] Buffer

할당된 버퍼에 대한 포인터를 받습니다.

반환 값

함수가 성공하면 반환 값이 NERR_Success.

함수가 실패하면 반환 값은 시스템 오류 코드입니다. 오류 코드 목록은 시스템 오류 코드를 참조하세요.

설명

ApiBuffer 함수를 성공적으로 실행하려면 특별한 그룹 멤버 자격이 필요하지 않습니다.

자세한 내용은 네트워크 관리 함수 버퍼 및 네트워크관리 함수 버퍼 길이를 참조하세요.

예제

다음 코드 샘플에서는 네트워크 관리 ApiBuffer 함수를 사용하는 방법을 보여 줍니다.

샘플은 먼저 NetApiBufferAllocate 함수를 호출하여 메모리를 할당한 다음 NetApiBufferSize 함수를 호출하여 할당된 메모리의 크기를 검색합니다. 이에 따라 샘플은 NetApiBufferReallocate 를 호출하여 메모리 할당의 크기를 변경합니다. 마지막으로 샘플은 NetApiBufferFree 를 호출하여 메모리를 해제합니다. 각 경우에 샘플은 성공 또는 실패를 나타내는 메시지를 출력합니다.

#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>
#include <lm.h>
#include <stdio.h>

#pragma comment(lib, "netapi32.lib")

void PrintError(LPSTR lpszApi, DWORD res);

int main()
{
   PUSER_INFO_10 p;
   DWORD res, dwSize;

   // Call the NetApiBufferAllocate function 
   //   to allocate the memory. If successful,
   //   print a message.
   //
   res = NetApiBufferAllocate(1024, (LPVOID *) &p);
   if(res == NERR_Success)
   {
      printf("NetApiBufferAllocate:   Allocated 1024 bytes.\n");

      // Call the NetApiBufferSize function 
      //   to retrieve the size of the allocated buffer.
      //   If successful, print the size.
      //
      res = NetApiBufferSize(p, &dwSize);
      if(res == NERR_Success)
      {
         printf("NetApiBufferSize:       Buffer has %u bytes.\n", dwSize);

         // Call the NetApiBufferReallocate function
         //   to change the size of the allocated memory.
         //   If successful, print the new size of the buffer.
         //
         res = NetApiBufferReallocate(p, dwSize * 2, (LPVOID *) &p);   
         if(res == NERR_Success)
            printf("NetApiBufferReallocate: Re-Allocated %u bytes.\n", dwSize * 2);
         else
            PrintError("NetApiBufferReallocate", res);

         // Call the NetApiBufferFree function
         //    to free the allocated memory.
         //    If successful, print a message.
         //
         res = NetApiBufferFree(p);
         if(res == NERR_Success)
            printf("Freed Buffer\n");

         else
            PrintError("NetApiBufferFree", res);
      }
      else
         PrintError("NetApiBufferSize", res);
   }         
   else
      PrintError("NetApiBufferAllocate", res);
   return 0;
}

void PrintError(LPSTR lpszApi, DWORD res)
{
   printf("%s: Error %u\n", lpszApi, res);
   return;
}

요구 사항

   
지원되는 최소 클라이언트 Windows 2000 Professional[데스크톱 앱만]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 lmapibuf.h(Lm.h 포함)
라이브러리 Netapi32.lib
DLL Netapi32.dll

참고 항목

API 버퍼 함수

NetApiBufferFree

NetApiBufferReallocate

네트워크 관리 함수

네트워크 관리 개요