ホーム › NetworkManagement.Snmp › SnmpCreatePdu
SnmpCreatePdu
関数WinSNMPで指定種類のPDU(プロトコルデータ単位)を作成する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| session | INT_PTR | in | 使用するWinSNMPセッションハンドル。 |
| PDU_type | SNMP_PDU_TYPE | in | 作成するPDUの種別(SNMP_PDU_TYPE)。GET/SET/RESPONSE等。 |
| request_id | INT | in | PDUに設定する要求ID。 |
| error_status | INT | in | PDUに設定するエラーステータス値。 |
| error_index | INT | in | PDUに設定するエラーインデックス値。 |
| varbindlist | INT_PTR | in | PDUに関連付ける変数バインドリストのハンドル。 |
戻り値の型: 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_PTRfunction 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)。const std = @import("std");
extern "wsnmp32" 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
) callconv(std.os.windows.WINAPI) isize;proc SnmpCreatePdu(
session: int, # INT_PTR
PDU_type: uint32, # SNMP_PDU_TYPE
request_id: int32, # INT
error_status: int32, # INT
error_index: int32, # INT
varbindlist: int # INT_PTR
): int {.importc: "SnmpCreatePdu", stdcall, dynlib: "wsnmp32.dll".}pragma(lib, "wsnmp32");
extern(Windows)
ptrdiff_t SnmpCreatePdu(
ptrdiff_t session, // INT_PTR
uint PDU_type, // SNMP_PDU_TYPE
int request_id, // INT
int error_status, // INT
int error_index, // INT
ptrdiff_t varbindlist // INT_PTR
);ccall((:SnmpCreatePdu, "wsnmp32.dll"), stdcall, Int,
(Int, UInt32, Int32, Int32, Int32, Int),
session, PDU_type, request_id, error_status, error_index, varbindlist)
# session : INT_PTR -> Int
# PDU_type : SNMP_PDU_TYPE -> UInt32
# request_id : INT -> Int32
# error_status : INT -> Int32
# error_index : INT -> Int32
# varbindlist : INT_PTR -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t SnmpCreatePdu(
intptr_t session,
uint32_t PDU_type,
int32_t request_id,
int32_t error_status,
int32_t error_index,
intptr_t varbindlist);
]]
local wsnmp32 = ffi.load("wsnmp32")
-- wsnmp32.SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
-- session : INT_PTR
-- PDU_type : SNMP_PDU_TYPE
-- request_id : INT
-- error_status : INT
-- error_index : INT
-- varbindlist : INT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('wsnmp32.dll');
const SnmpCreatePdu = lib.func('__stdcall', 'SnmpCreatePdu', 'intptr_t', ['intptr_t', 'uint32_t', 'int32_t', 'int32_t', 'int32_t', 'intptr_t']);
// SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
// session : INT_PTR -> 'intptr_t'
// PDU_type : SNMP_PDU_TYPE -> 'uint32_t'
// request_id : INT -> 'int32_t'
// error_status : INT -> 'int32_t'
// error_index : INT -> 'int32_t'
// varbindlist : INT_PTR -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("wsnmp32.dll", {
SnmpCreatePdu: { parameters: ["isize", "u32", "i32", "i32", "i32", "isize"], result: "isize" },
});
// lib.symbols.SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist)
// session : INT_PTR -> "isize"
// PDU_type : SNMP_PDU_TYPE -> "u32"
// request_id : INT -> "i32"
// error_status : INT -> "i32"
// error_index : INT -> "i32"
// varbindlist : INT_PTR -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t SnmpCreatePdu(
intptr_t session,
uint32_t PDU_type,
int32_t request_id,
int32_t error_status,
int32_t error_index,
intptr_t varbindlist);
C, "wsnmp32.dll");
// $ffi->SnmpCreatePdu(session, PDU_type, request_id, error_status, error_index, varbindlist);
// session : INT_PTR
// PDU_type : SNMP_PDU_TYPE
// request_id : INT
// error_status : INT
// error_index : INT
// varbindlist : INT_PTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wsnmp32 extends StdCallLibrary {
Wsnmp32 INSTANCE = Native.load("wsnmp32", Wsnmp32.class);
long SnmpCreatePdu(
long session, // INT_PTR
int PDU_type, // SNMP_PDU_TYPE
int request_id, // INT
int error_status, // INT
int error_index, // INT
long varbindlist // INT_PTR
);
}@[Link("wsnmp32")]
lib Libwsnmp32
fun SnmpCreatePdu = SnmpCreatePdu(
session : LibC::SSizeT, # INT_PTR
PDU_type : UInt32, # SNMP_PDU_TYPE
request_id : Int32, # INT
error_status : Int32, # INT
error_index : Int32, # INT
varbindlist : LibC::SSizeT # INT_PTR
) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SnmpCreatePduNative = IntPtr Function(IntPtr, Uint32, Int32, Int32, Int32, IntPtr);
typedef SnmpCreatePduDart = int Function(int, int, int, int, int, int);
final SnmpCreatePdu = DynamicLibrary.open('wsnmp32.dll')
.lookupFunction<SnmpCreatePduNative, SnmpCreatePduDart>('SnmpCreatePdu');
// session : INT_PTR -> IntPtr
// PDU_type : SNMP_PDU_TYPE -> Uint32
// request_id : INT -> Int32
// error_status : INT -> Int32
// error_index : INT -> Int32
// varbindlist : INT_PTR -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SnmpCreatePdu"
c_SnmpCreatePdu :: CIntPtr -> Word32 -> Int32 -> Int32 -> Int32 -> CIntPtr -> IO CIntPtr
-- session : INT_PTR -> CIntPtr
-- PDU_type : SNMP_PDU_TYPE -> Word32
-- request_id : INT -> Int32
-- error_status : INT -> Int32
-- error_index : INT -> Int32
-- varbindlist : INT_PTR -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let snmpcreatepdu =
foreign "SnmpCreatePdu"
(intptr_t @-> uint32_t @-> int32_t @-> int32_t @-> int32_t @-> intptr_t @-> returning intptr_t)
(* session : INT_PTR -> intptr_t *)
(* PDU_type : SNMP_PDU_TYPE -> uint32_t *)
(* request_id : INT -> int32_t *)
(* error_status : INT -> int32_t *)
(* error_index : INT -> int32_t *)
(* varbindlist : INT_PTR -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wsnmp32 (t "wsnmp32.dll"))
(cffi:use-foreign-library wsnmp32)
(cffi:defcfun ("SnmpCreatePdu" snmp-create-pdu :convention :stdcall) :int64
(session :int64) ; INT_PTR
(pdu-type :uint32) ; SNMP_PDU_TYPE
(request-id :int32) ; INT
(error-status :int32) ; INT
(error-index :int32) ; INT
(varbindlist :int64)) ; INT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SnmpCreatePdu = Win32::API::More->new('wsnmp32',
'LPARAM SnmpCreatePdu(LPARAM session, DWORD PDU_type, int request_id, int error_status, int error_index, LPARAM varbindlist)');
# my $ret = $SnmpCreatePdu->Call($session, $PDU_type, $request_id, $error_status, $error_index, $varbindlist);
# session : INT_PTR -> LPARAM
# PDU_type : SNMP_PDU_TYPE -> DWORD
# request_id : INT -> int
# error_status : INT -> int
# error_index : INT -> int
# varbindlist : INT_PTR -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型