ホーム › NetworkManagement.Snmp › SnmpCreateVbl
SnmpCreateVbl
関数OIDと値からWinSNMPの変数バインドリストを作成する。
シグネチャ
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpCreateVbl(
INT_PTR session,
smiOID* name,
smiVALUE* value
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| session | INT_PTR | in | 使用するWinSNMPセッションハンドル。 |
| name | smiOID* | inout | 最初の変数バインドのOID(smiOID)ポインタ。NULLで空リストを作成可。 |
| value | smiVALUE* | inout | 最初の変数バインドの値(smiVALUE)ポインタ。NULL可。 |
戻り値の型: INT_PTR
各言語での呼び出し定義
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpCreateVbl(
INT_PTR session,
smiOID* name,
smiVALUE* value
);[DllImport("wsnmp32.dll", ExactSpelling = true)]
static extern IntPtr SnmpCreateVbl(
IntPtr session, // INT_PTR
IntPtr name, // smiOID* in/out
IntPtr value // smiVALUE* in/out
);<DllImport("wsnmp32.dll", ExactSpelling:=True)>
Public Shared Function SnmpCreateVbl(
session As IntPtr, ' INT_PTR
name As IntPtr, ' smiOID* in/out
value As IntPtr ' smiVALUE* in/out
) As IntPtr
End Function' session : INT_PTR
' name : smiOID* in/out
' value : smiVALUE* in/out
Declare PtrSafe Function SnmpCreateVbl Lib "wsnmp32" ( _
ByVal session As LongPtr, _
ByVal name As LongPtr, _
ByVal value As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpCreateVbl = ctypes.windll.wsnmp32.SnmpCreateVbl
SnmpCreateVbl.restype = ctypes.c_ssize_t
SnmpCreateVbl.argtypes = [
ctypes.c_ssize_t, # session : INT_PTR
ctypes.c_void_p, # name : smiOID* in/out
ctypes.c_void_p, # value : smiVALUE* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('wsnmp32.dll')
SnmpCreateVbl = Fiddle::Function.new(
lib['SnmpCreateVbl'],
[
Fiddle::TYPE_INTPTR_T, # session : INT_PTR
Fiddle::TYPE_VOIDP, # name : smiOID* in/out
Fiddle::TYPE_VOIDP, # value : smiVALUE* in/out
],
Fiddle::TYPE_INTPTR_T)#[link(name = "wsnmp32")]
extern "system" {
fn SnmpCreateVbl(
session: isize, // INT_PTR
name: *mut smiOID, // smiOID* in/out
value: *mut smiVALUE // smiVALUE* in/out
) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("wsnmp32.dll")]
public static extern IntPtr SnmpCreateVbl(IntPtr session, IntPtr name, IntPtr value);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wsnmp32_SnmpCreateVbl' -Namespace Win32 -PassThru
# $api::SnmpCreateVbl(session, name, value)#uselib "wsnmp32.dll"
#func global SnmpCreateVbl "SnmpCreateVbl" sptr, sptr, sptr
; SnmpCreateVbl session, varptr(name), varptr(value) ; 戻り値は stat
; session : INT_PTR -> "sptr"
; name : smiOID* in/out -> "sptr"
; value : smiVALUE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "wsnmp32.dll" #cfunc global SnmpCreateVbl "SnmpCreateVbl" sptr, var, var ; res = SnmpCreateVbl(session, name, value) ; session : INT_PTR -> "sptr" ; name : smiOID* in/out -> "var" ; value : smiVALUE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "wsnmp32.dll" #cfunc global SnmpCreateVbl "SnmpCreateVbl" sptr, sptr, sptr ; res = SnmpCreateVbl(session, varptr(name), varptr(value)) ; session : INT_PTR -> "sptr" ; name : smiOID* in/out -> "sptr" ; value : smiVALUE* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT_PTR SnmpCreateVbl(INT_PTR session, smiOID* name, smiVALUE* value) #uselib "wsnmp32.dll" #cfunc global SnmpCreateVbl "SnmpCreateVbl" intptr, var, var ; res = SnmpCreateVbl(session, name, value) ; session : INT_PTR -> "intptr" ; name : smiOID* in/out -> "var" ; value : smiVALUE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT_PTR SnmpCreateVbl(INT_PTR session, smiOID* name, smiVALUE* value) #uselib "wsnmp32.dll" #cfunc global SnmpCreateVbl "SnmpCreateVbl" intptr, intptr, intptr ; res = SnmpCreateVbl(session, varptr(name), varptr(value)) ; session : INT_PTR -> "intptr" ; name : smiOID* in/out -> "intptr" ; value : smiVALUE* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsnmp32 = windows.NewLazySystemDLL("wsnmp32.dll")
procSnmpCreateVbl = wsnmp32.NewProc("SnmpCreateVbl")
)
// session (INT_PTR), name (smiOID* in/out), value (smiVALUE* in/out)
r1, _, err := procSnmpCreateVbl.Call(
uintptr(session),
uintptr(name),
uintptr(value),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INT_PTRfunction SnmpCreateVbl(
session: NativeInt; // INT_PTR
name: Pointer; // smiOID* in/out
value: Pointer // smiVALUE* in/out
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpCreateVbl';result := DllCall("wsnmp32\SnmpCreateVbl"
, "Ptr", session ; INT_PTR
, "Ptr", name ; smiOID* in/out
, "Ptr", value ; smiVALUE* in/out
, "Ptr") ; return: INT_PTR●SnmpCreateVbl(session, name, value) = DLL("wsnmp32.dll", "int SnmpCreateVbl(int, void*, void*)")
# 呼び出し: SnmpCreateVbl(session, name, value)
# session : INT_PTR -> "int"
# name : smiOID* in/out -> "void*"
# value : smiVALUE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wsnmp32" fn SnmpCreateVbl(
session: isize, // INT_PTR
name: [*c]smiOID, // smiOID* in/out
value: [*c]smiVALUE // smiVALUE* in/out
) callconv(std.os.windows.WINAPI) isize;proc SnmpCreateVbl(
session: int, # INT_PTR
name: ptr smiOID, # smiOID* in/out
value: ptr smiVALUE # smiVALUE* in/out
): int {.importc: "SnmpCreateVbl", stdcall, dynlib: "wsnmp32.dll".}pragma(lib, "wsnmp32");
extern(Windows)
ptrdiff_t SnmpCreateVbl(
ptrdiff_t session, // INT_PTR
smiOID* name, // smiOID* in/out
smiVALUE* value // smiVALUE* in/out
);ccall((:SnmpCreateVbl, "wsnmp32.dll"), stdcall, Int,
(Int, Ptr{smiOID}, Ptr{smiVALUE}),
session, name, value)
# session : INT_PTR -> Int
# name : smiOID* in/out -> Ptr{smiOID}
# value : smiVALUE* in/out -> Ptr{smiVALUE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t SnmpCreateVbl(
intptr_t session,
void* name,
void* value);
]]
local wsnmp32 = ffi.load("wsnmp32")
-- wsnmp32.SnmpCreateVbl(session, name, value)
-- session : INT_PTR
-- name : smiOID* in/out
-- value : smiVALUE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('wsnmp32.dll');
const SnmpCreateVbl = lib.func('__stdcall', 'SnmpCreateVbl', 'intptr_t', ['intptr_t', 'void *', 'void *']);
// SnmpCreateVbl(session, name, value)
// session : INT_PTR -> 'intptr_t'
// name : smiOID* in/out -> 'void *'
// value : smiVALUE* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("wsnmp32.dll", {
SnmpCreateVbl: { parameters: ["isize", "pointer", "pointer"], result: "isize" },
});
// lib.symbols.SnmpCreateVbl(session, name, value)
// session : INT_PTR -> "isize"
// name : smiOID* in/out -> "pointer"
// value : smiVALUE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t SnmpCreateVbl(
intptr_t session,
void* name,
void* value);
C, "wsnmp32.dll");
// $ffi->SnmpCreateVbl(session, name, value);
// session : INT_PTR
// name : smiOID* in/out
// value : smiVALUE* in/out
// 構造体/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 SnmpCreateVbl(
long session, // INT_PTR
Pointer name, // smiOID* in/out
Pointer value // smiVALUE* in/out
);
}@[Link("wsnmp32")]
lib Libwsnmp32
fun SnmpCreateVbl = SnmpCreateVbl(
session : LibC::SSizeT, # INT_PTR
name : smiOID*, # smiOID* in/out
value : smiVALUE* # smiVALUE* in/out
) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SnmpCreateVblNative = IntPtr Function(IntPtr, Pointer<Void>, Pointer<Void>);
typedef SnmpCreateVblDart = int Function(int, Pointer<Void>, Pointer<Void>);
final SnmpCreateVbl = DynamicLibrary.open('wsnmp32.dll')
.lookupFunction<SnmpCreateVblNative, SnmpCreateVblDart>('SnmpCreateVbl');
// session : INT_PTR -> IntPtr
// name : smiOID* in/out -> Pointer<Void>
// value : smiVALUE* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SnmpCreateVbl(
session: NativeInt; // INT_PTR
name: Pointer; // smiOID* in/out
value: Pointer // smiVALUE* in/out
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpCreateVbl';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SnmpCreateVbl"
c_SnmpCreateVbl :: CIntPtr -> Ptr () -> Ptr () -> IO CIntPtr
-- session : INT_PTR -> CIntPtr
-- name : smiOID* in/out -> Ptr ()
-- value : smiVALUE* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let snmpcreatevbl =
foreign "SnmpCreateVbl"
(intptr_t @-> (ptr void) @-> (ptr void) @-> returning intptr_t)
(* session : INT_PTR -> intptr_t *)
(* name : smiOID* in/out -> (ptr void) *)
(* value : smiVALUE* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wsnmp32 (t "wsnmp32.dll"))
(cffi:use-foreign-library wsnmp32)
(cffi:defcfun ("SnmpCreateVbl" snmp-create-vbl :convention :stdcall) :int64
(session :int64) ; INT_PTR
(name :pointer) ; smiOID* in/out
(value :pointer)) ; smiVALUE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SnmpCreateVbl = Win32::API::More->new('wsnmp32',
'LPARAM SnmpCreateVbl(LPARAM session, LPVOID name, LPVOID value)');
# my $ret = $SnmpCreateVbl->Call($session, $name, $value);
# session : INT_PTR -> LPARAM
# name : smiOID* in/out -> LPVOID
# value : smiVALUE* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型