Share via


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 (include Lm.h)
Library Netapi32.lib
[DLL] Netapi32.dll

関連項目

Api バッファー関数

NetApiBufferFree

NetApiBufferReallocate

ネットワーク管理機能

ネットワーク管理の概要