ホーム › NetworkManagement.Snmp › SnmpMgrRequest
SnmpMgrRequest
関数SNMPエージェントに要求を送り変数バインドを取得する。
シグネチャ
// mgmtapi.dll
#include <windows.h>
INT SnmpMgrRequest(
void* session,
BYTE requestType,
SnmpVarBindList* variableBindings,
SNMP_ERROR_STATUS* errorStatus,
INT* errorIndex
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| session | void* | inout |
| requestType | BYTE | in |
| variableBindings | SnmpVarBindList* | inout |
| errorStatus | SNMP_ERROR_STATUS* | inout |
| errorIndex | INT* | inout |
戻り値の型: INT
各言語での呼び出し定義
// mgmtapi.dll
#include <windows.h>
INT SnmpMgrRequest(
void* session,
BYTE requestType,
SnmpVarBindList* variableBindings,
SNMP_ERROR_STATUS* errorStatus,
INT* errorIndex
);[DllImport("mgmtapi.dll", SetLastError = true, ExactSpelling = true)]
static extern int SnmpMgrRequest(
IntPtr session, // void* in/out
byte requestType, // BYTE
IntPtr variableBindings, // SnmpVarBindList* in/out
ref uint errorStatus, // SNMP_ERROR_STATUS* in/out
ref int errorIndex // INT* in/out
);<DllImport("mgmtapi.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SnmpMgrRequest(
session As IntPtr, ' void* in/out
requestType As Byte, ' BYTE
variableBindings As IntPtr, ' SnmpVarBindList* in/out
ByRef errorStatus As UInteger, ' SNMP_ERROR_STATUS* in/out
ByRef errorIndex As Integer ' INT* in/out
) As Integer
End Function' session : void* in/out
' requestType : BYTE
' variableBindings : SnmpVarBindList* in/out
' errorStatus : SNMP_ERROR_STATUS* in/out
' errorIndex : INT* in/out
Declare PtrSafe Function SnmpMgrRequest Lib "mgmtapi" ( _
ByVal session As LongPtr, _
ByVal requestType As Byte, _
ByVal variableBindings As LongPtr, _
ByRef errorStatus As Long, _
ByRef errorIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpMgrRequest = ctypes.windll.mgmtapi.SnmpMgrRequest
SnmpMgrRequest.restype = ctypes.c_int
SnmpMgrRequest.argtypes = [
ctypes.POINTER(None), # session : void* in/out
ctypes.c_ubyte, # requestType : BYTE
ctypes.c_void_p, # variableBindings : SnmpVarBindList* in/out
ctypes.c_void_p, # errorStatus : SNMP_ERROR_STATUS* in/out
ctypes.POINTER(ctypes.c_int), # errorIndex : INT* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mgmtapi.dll')
SnmpMgrRequest = Fiddle::Function.new(
lib['SnmpMgrRequest'],
[
Fiddle::TYPE_VOIDP, # session : void* in/out
-Fiddle::TYPE_CHAR, # requestType : BYTE
Fiddle::TYPE_VOIDP, # variableBindings : SnmpVarBindList* in/out
Fiddle::TYPE_VOIDP, # errorStatus : SNMP_ERROR_STATUS* in/out
Fiddle::TYPE_VOIDP, # errorIndex : INT* in/out
],
Fiddle::TYPE_INT)#[link(name = "mgmtapi")]
extern "system" {
fn SnmpMgrRequest(
session: *mut (), // void* in/out
requestType: u8, // BYTE
variableBindings: *mut SnmpVarBindList, // SnmpVarBindList* in/out
errorStatus: *mut u32, // SNMP_ERROR_STATUS* in/out
errorIndex: *mut i32 // INT* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mgmtapi.dll", SetLastError = true)]
public static extern int SnmpMgrRequest(IntPtr session, byte requestType, IntPtr variableBindings, ref uint errorStatus, ref int errorIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mgmtapi_SnmpMgrRequest' -Namespace Win32 -PassThru
# $api::SnmpMgrRequest(session, requestType, variableBindings, errorStatus, errorIndex)#uselib "mgmtapi.dll"
#func global SnmpMgrRequest "SnmpMgrRequest" sptr, sptr, sptr, sptr, sptr
; SnmpMgrRequest session, requestType, varptr(variableBindings), errorStatus, varptr(errorIndex) ; 戻り値は stat
; session : void* in/out -> "sptr"
; requestType : BYTE -> "sptr"
; variableBindings : SnmpVarBindList* in/out -> "sptr"
; errorStatus : SNMP_ERROR_STATUS* in/out -> "sptr"
; errorIndex : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mgmtapi.dll" #cfunc global SnmpMgrRequest "SnmpMgrRequest" sptr, int, var, int, var ; res = SnmpMgrRequest(session, requestType, variableBindings, errorStatus, errorIndex) ; session : void* in/out -> "sptr" ; requestType : BYTE -> "int" ; variableBindings : SnmpVarBindList* in/out -> "var" ; errorStatus : SNMP_ERROR_STATUS* in/out -> "int" ; errorIndex : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mgmtapi.dll" #cfunc global SnmpMgrRequest "SnmpMgrRequest" sptr, int, sptr, int, sptr ; res = SnmpMgrRequest(session, requestType, varptr(variableBindings), errorStatus, varptr(errorIndex)) ; session : void* in/out -> "sptr" ; requestType : BYTE -> "int" ; variableBindings : SnmpVarBindList* in/out -> "sptr" ; errorStatus : SNMP_ERROR_STATUS* in/out -> "int" ; errorIndex : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT SnmpMgrRequest(void* session, BYTE requestType, SnmpVarBindList* variableBindings, SNMP_ERROR_STATUS* errorStatus, INT* errorIndex) #uselib "mgmtapi.dll" #cfunc global SnmpMgrRequest "SnmpMgrRequest" intptr, int, var, int, var ; res = SnmpMgrRequest(session, requestType, variableBindings, errorStatus, errorIndex) ; session : void* in/out -> "intptr" ; requestType : BYTE -> "int" ; variableBindings : SnmpVarBindList* in/out -> "var" ; errorStatus : SNMP_ERROR_STATUS* in/out -> "int" ; errorIndex : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SnmpMgrRequest(void* session, BYTE requestType, SnmpVarBindList* variableBindings, SNMP_ERROR_STATUS* errorStatus, INT* errorIndex) #uselib "mgmtapi.dll" #cfunc global SnmpMgrRequest "SnmpMgrRequest" intptr, int, intptr, int, intptr ; res = SnmpMgrRequest(session, requestType, varptr(variableBindings), errorStatus, varptr(errorIndex)) ; session : void* in/out -> "intptr" ; requestType : BYTE -> "int" ; variableBindings : SnmpVarBindList* in/out -> "intptr" ; errorStatus : SNMP_ERROR_STATUS* in/out -> "int" ; errorIndex : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mgmtapi = windows.NewLazySystemDLL("mgmtapi.dll")
procSnmpMgrRequest = mgmtapi.NewProc("SnmpMgrRequest")
)
// session (void* in/out), requestType (BYTE), variableBindings (SnmpVarBindList* in/out), errorStatus (SNMP_ERROR_STATUS* in/out), errorIndex (INT* in/out)
r1, _, err := procSnmpMgrRequest.Call(
uintptr(session),
uintptr(requestType),
uintptr(variableBindings),
uintptr(errorStatus),
uintptr(errorIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SnmpMgrRequest(
session: Pointer; // void* in/out
requestType: Byte; // BYTE
variableBindings: Pointer; // SnmpVarBindList* in/out
errorStatus: Pointer; // SNMP_ERROR_STATUS* in/out
errorIndex: Pointer // INT* in/out
): Integer; stdcall;
external 'mgmtapi.dll' name 'SnmpMgrRequest';result := DllCall("mgmtapi\SnmpMgrRequest"
, "Ptr", session ; void* in/out
, "UChar", requestType ; BYTE
, "Ptr", variableBindings ; SnmpVarBindList* in/out
, "Ptr", errorStatus ; SNMP_ERROR_STATUS* in/out
, "Ptr", errorIndex ; INT* in/out
, "Int") ; return: INT●SnmpMgrRequest(session, requestType, variableBindings, errorStatus, errorIndex) = DLL("mgmtapi.dll", "int SnmpMgrRequest(void*, byte, void*, void*, void*)")
# 呼び出し: SnmpMgrRequest(session, requestType, variableBindings, errorStatus, errorIndex)
# session : void* in/out -> "void*"
# requestType : BYTE -> "byte"
# variableBindings : SnmpVarBindList* in/out -> "void*"
# errorStatus : SNMP_ERROR_STATUS* in/out -> "void*"
# errorIndex : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。