Win32 API 日本語リファレンス
ホームNetworkManagement.Snmp › SnmpCreatePdu

SnmpCreatePdu

関数
WinSNMPで指定種類のPDU(プロトコルデータ単位)を作成する。
DLLwsnmp32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// wsnmp32.dll
#include <windows.h>

INT_PTR SnmpCreatePdu(
    INT_PTR session,
    SNMP_PDU_TYPE PDU_type,
    INT request_id,
    INT error_status,
    INT error_index,
    INT_PTR varbindlist
);

パラメーター

名前方向
sessionINT_PTRin
PDU_typeSNMP_PDU_TYPEin
request_idINTin
error_statusINTin
error_indexINTin
varbindlistINT_PTRin

戻り値の型: INT_PTR

各言語での呼び出し定義

// wsnmp32.dll
#include <windows.h>

INT_PTR SnmpCreatePdu(
    INT_PTR session,
    SNMP_PDU_TYPE PDU_type,
    INT request_id,
    INT error_status,
    INT error_index,
    INT_PTR varbindlist
);
[DllImport("wsnmp32.dll", ExactSpelling = true)]
static extern IntPtr SnmpCreatePdu(
    IntPtr session,   // INT_PTR
    uint PDU_type,   // SNMP_PDU_TYPE
    int request_id,   // INT
    int error_status,   // INT
    int error_index,   // INT
    IntPtr varbindlist   // INT_PTR
);
<DllImport("wsnmp32.dll", ExactSpelling:=True)>
Public Shared Function SnmpCreatePdu(
    session As IntPtr,   ' INT_PTR
    PDU_type As UInteger,   ' SNMP_PDU_TYPE
    request_id As Integer,   ' INT
    error_status As Integer,   ' INT
    error_index As Integer,   ' INT
    varbindlist As IntPtr   ' INT_PTR
) As IntPtr
End Function
' session : INT_PTR
' PDU_type : SNMP_PDU_TYPE
' request_id : INT
' error_status : INT
' error_index : INT
' varbindlist : INT_PTR
Declare PtrSafe Function SnmpCreatePdu Lib "wsnmp32" ( _
    ByVal session As LongPtr, _
    ByVal PDU_type As Long, _
    ByVal request_id As Long, _
    ByVal error_status As Long, _
    ByVal error_index As Long, _
    ByVal varbindlist As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SnmpCreatePdu = ctypes.windll.wsnmp32.SnmpCreatePdu
SnmpCreatePdu.restype = ctypes.c_ssize_t
SnmpCreatePdu.argtypes = [
    ctypes.c_ssize_t,  # session : INT_PTR
    wintypes.DWORD,  # PDU_type : SNMP_PDU_TYPE
    ctypes.c_int,  # request_id : INT
    ctypes.c_int,  # error_status : INT
    ctypes.c_int,  # error_index : INT
    ctypes.c_ssize_t,  # varbindlist : INT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('wsnmp32.dll')
SnmpCreatePdu = Fiddle::Function.new(
  lib['SnmpCreatePdu'],
  [
    Fiddle::TYPE_INTPTR_T,  # session : INT_PTR
    -Fiddle::TYPE_INT,  # PDU_type : SNMP_PDU_TYPE
    Fiddle::TYPE_INT,  # request_id : INT
    Fiddle::TYPE_INT,  # error_status : INT
    Fiddle::TYPE_INT,  # error_index : INT
    Fiddle::TYPE_INTPTR_T,  # varbindlist : INT_PTR
  ],
  Fiddle::TYPE_INTPTR_T)
#[link(name = "wsnmp32")]
extern "system" {
    fn SnmpCreatePdu(
        session: isize,  // INT_PTR
        PDU_type: u32,  // SNMP_PDU_TYPE
        request_id: i32,  // INT
        error_status: i32,  // INT
        error_index: i32,  // INT
        varbindlist: isize  // INT_PTR
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("wsnmp32.dll")]
public static extern IntPtr SnmpCreatePdu(IntPtr session, uint PDU_type, int request_id, int error_status, int error_index, IntPtr varbindlist);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wsnmp32_SnmpCreatePdu' -Namespace Win32 -PassThru
# $api::SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
#uselib "wsnmp32.dll"
#func global SnmpCreatePdu "SnmpCreatePdu" sptr, sptr, sptr, sptr, sptr, sptr
; SnmpCreatePdu session, PDU_type, request_id, error_status, error_index, varbindlist   ; 戻り値は stat
; session : INT_PTR -> "sptr"
; PDU_type : SNMP_PDU_TYPE -> "sptr"
; request_id : INT -> "sptr"
; error_status : INT -> "sptr"
; error_index : INT -> "sptr"
; varbindlist : INT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "wsnmp32.dll"
#cfunc global SnmpCreatePdu "SnmpCreatePdu" sptr, int, int, int, int, sptr
; res = SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
; session : INT_PTR -> "sptr"
; PDU_type : SNMP_PDU_TYPE -> "int"
; request_id : INT -> "int"
; error_status : INT -> "int"
; error_index : INT -> "int"
; varbindlist : INT_PTR -> "sptr"
; INT_PTR SnmpCreatePdu(INT_PTR session, SNMP_PDU_TYPE PDU_type, INT request_id, INT error_status, INT error_index, INT_PTR varbindlist)
#uselib "wsnmp32.dll"
#cfunc global SnmpCreatePdu "SnmpCreatePdu" intptr, int, int, int, int, intptr
; res = SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
; session : INT_PTR -> "intptr"
; PDU_type : SNMP_PDU_TYPE -> "int"
; request_id : INT -> "int"
; error_status : INT -> "int"
; error_index : INT -> "int"
; varbindlist : INT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wsnmp32 = windows.NewLazySystemDLL("wsnmp32.dll")
	procSnmpCreatePdu = wsnmp32.NewProc("SnmpCreatePdu")
)

// session (INT_PTR), PDU_type (SNMP_PDU_TYPE), request_id (INT), error_status (INT), error_index (INT), varbindlist (INT_PTR)
r1, _, err := procSnmpCreatePdu.Call(
	uintptr(session),
	uintptr(PDU_type),
	uintptr(request_id),
	uintptr(error_status),
	uintptr(error_index),
	uintptr(varbindlist),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT_PTR
function SnmpCreatePdu(
  session: NativeInt;   // INT_PTR
  PDU_type: DWORD;   // SNMP_PDU_TYPE
  request_id: Integer;   // INT
  error_status: Integer;   // INT
  error_index: Integer;   // INT
  varbindlist: NativeInt   // INT_PTR
): NativeInt; stdcall;
  external 'wsnmp32.dll' name 'SnmpCreatePdu';
result := DllCall("wsnmp32\SnmpCreatePdu"
    , "Ptr", session   ; INT_PTR
    , "UInt", PDU_type   ; SNMP_PDU_TYPE
    , "Int", request_id   ; INT
    , "Int", error_status   ; INT
    , "Int", error_index   ; INT
    , "Ptr", varbindlist   ; INT_PTR
    , "Ptr")   ; return: INT_PTR
●SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist) = DLL("wsnmp32.dll", "int SnmpCreatePdu(int, dword, int, int, int, int)")
# 呼び出し: SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
# session : INT_PTR -> "int"
# PDU_type : SNMP_PDU_TYPE -> "dword"
# request_id : INT -> "int"
# error_status : INT -> "int"
# error_index : INT -> "int"
# varbindlist : INT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。