ホーム › NetworkManagement.Snmp › SnmpDecodeMsg
SnmpDecodeMsg
関数受信バイト列をデコードしWinSNMPメッセージに復元する。
シグネチャ
// wsnmp32.dll
#include <windows.h>
DWORD SnmpDecodeMsg(
INT_PTR session,
INT_PTR* srcEntity,
INT_PTR* dstEntity,
INT_PTR* context,
INT_PTR* pdu,
smiOCTETS* msgBufDesc
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| session | INT_PTR | in |
| srcEntity | INT_PTR* | inout |
| dstEntity | INT_PTR* | inout |
| context | INT_PTR* | inout |
| pdu | INT_PTR* | inout |
| msgBufDesc | smiOCTETS* | inout |
戻り値の型: DWORD
各言語での呼び出し定義
// wsnmp32.dll
#include <windows.h>
DWORD SnmpDecodeMsg(
INT_PTR session,
INT_PTR* srcEntity,
INT_PTR* dstEntity,
INT_PTR* context,
INT_PTR* pdu,
smiOCTETS* msgBufDesc
);[DllImport("wsnmp32.dll", ExactSpelling = true)]
static extern uint SnmpDecodeMsg(
IntPtr session, // INT_PTR
ref IntPtr srcEntity, // INT_PTR* in/out
ref IntPtr dstEntity, // INT_PTR* in/out
ref IntPtr context, // INT_PTR* in/out
ref IntPtr pdu, // INT_PTR* in/out
IntPtr msgBufDesc // smiOCTETS* in/out
);<DllImport("wsnmp32.dll", ExactSpelling:=True)>
Public Shared Function SnmpDecodeMsg(
session As IntPtr, ' INT_PTR
ByRef srcEntity As IntPtr, ' INT_PTR* in/out
ByRef dstEntity As IntPtr, ' INT_PTR* in/out
ByRef context As IntPtr, ' INT_PTR* in/out
ByRef pdu As IntPtr, ' INT_PTR* in/out
msgBufDesc As IntPtr ' smiOCTETS* in/out
) As UInteger
End Function' session : INT_PTR
' srcEntity : INT_PTR* in/out
' dstEntity : INT_PTR* in/out
' context : INT_PTR* in/out
' pdu : INT_PTR* in/out
' msgBufDesc : smiOCTETS* in/out
Declare PtrSafe Function SnmpDecodeMsg Lib "wsnmp32" ( _
ByVal session As LongPtr, _
ByRef srcEntity As LongPtr, _
ByRef dstEntity As LongPtr, _
ByRef context As LongPtr, _
ByRef pdu As LongPtr, _
ByVal msgBufDesc As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpDecodeMsg = ctypes.windll.wsnmp32.SnmpDecodeMsg
SnmpDecodeMsg.restype = wintypes.DWORD
SnmpDecodeMsg.argtypes = [
ctypes.c_ssize_t, # session : INT_PTR
ctypes.POINTER(ctypes.c_ssize_t), # srcEntity : INT_PTR* in/out
ctypes.POINTER(ctypes.c_ssize_t), # dstEntity : INT_PTR* in/out
ctypes.POINTER(ctypes.c_ssize_t), # context : INT_PTR* in/out
ctypes.POINTER(ctypes.c_ssize_t), # pdu : INT_PTR* in/out
ctypes.c_void_p, # msgBufDesc : smiOCTETS* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('wsnmp32.dll')
SnmpDecodeMsg = Fiddle::Function.new(
lib['SnmpDecodeMsg'],
[
Fiddle::TYPE_INTPTR_T, # session : INT_PTR
Fiddle::TYPE_VOIDP, # srcEntity : INT_PTR* in/out
Fiddle::TYPE_VOIDP, # dstEntity : INT_PTR* in/out
Fiddle::TYPE_VOIDP, # context : INT_PTR* in/out
Fiddle::TYPE_VOIDP, # pdu : INT_PTR* in/out
Fiddle::TYPE_VOIDP, # msgBufDesc : smiOCTETS* in/out
],
-Fiddle::TYPE_INT)#[link(name = "wsnmp32")]
extern "system" {
fn SnmpDecodeMsg(
session: isize, // INT_PTR
srcEntity: *mut isize, // INT_PTR* in/out
dstEntity: *mut isize, // INT_PTR* in/out
context: *mut isize, // INT_PTR* in/out
pdu: *mut isize, // INT_PTR* in/out
msgBufDesc: *mut smiOCTETS // smiOCTETS* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("wsnmp32.dll")]
public static extern uint SnmpDecodeMsg(IntPtr session, ref IntPtr srcEntity, ref IntPtr dstEntity, ref IntPtr context, ref IntPtr pdu, IntPtr msgBufDesc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wsnmp32_SnmpDecodeMsg' -Namespace Win32 -PassThru
# $api::SnmpDecodeMsg(session, srcEntity, dstEntity, context, pdu, msgBufDesc)#uselib "wsnmp32.dll"
#func global SnmpDecodeMsg "SnmpDecodeMsg" sptr, sptr, sptr, sptr, sptr, sptr
; SnmpDecodeMsg session, varptr(srcEntity), varptr(dstEntity), varptr(context), varptr(pdu), varptr(msgBufDesc) ; 戻り値は stat
; session : INT_PTR -> "sptr"
; srcEntity : INT_PTR* in/out -> "sptr"
; dstEntity : INT_PTR* in/out -> "sptr"
; context : INT_PTR* in/out -> "sptr"
; pdu : INT_PTR* in/out -> "sptr"
; msgBufDesc : smiOCTETS* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "wsnmp32.dll" #cfunc global SnmpDecodeMsg "SnmpDecodeMsg" sptr, var, var, var, var, var ; res = SnmpDecodeMsg(session, srcEntity, dstEntity, context, pdu, msgBufDesc) ; session : INT_PTR -> "sptr" ; srcEntity : INT_PTR* in/out -> "var" ; dstEntity : INT_PTR* in/out -> "var" ; context : INT_PTR* in/out -> "var" ; pdu : INT_PTR* in/out -> "var" ; msgBufDesc : smiOCTETS* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "wsnmp32.dll" #cfunc global SnmpDecodeMsg "SnmpDecodeMsg" sptr, sptr, sptr, sptr, sptr, sptr ; res = SnmpDecodeMsg(session, varptr(srcEntity), varptr(dstEntity), varptr(context), varptr(pdu), varptr(msgBufDesc)) ; session : INT_PTR -> "sptr" ; srcEntity : INT_PTR* in/out -> "sptr" ; dstEntity : INT_PTR* in/out -> "sptr" ; context : INT_PTR* in/out -> "sptr" ; pdu : INT_PTR* in/out -> "sptr" ; msgBufDesc : smiOCTETS* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD SnmpDecodeMsg(INT_PTR session, INT_PTR* srcEntity, INT_PTR* dstEntity, INT_PTR* context, INT_PTR* pdu, smiOCTETS* msgBufDesc) #uselib "wsnmp32.dll" #cfunc global SnmpDecodeMsg "SnmpDecodeMsg" intptr, var, var, var, var, var ; res = SnmpDecodeMsg(session, srcEntity, dstEntity, context, pdu, msgBufDesc) ; session : INT_PTR -> "intptr" ; srcEntity : INT_PTR* in/out -> "var" ; dstEntity : INT_PTR* in/out -> "var" ; context : INT_PTR* in/out -> "var" ; pdu : INT_PTR* in/out -> "var" ; msgBufDesc : smiOCTETS* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD SnmpDecodeMsg(INT_PTR session, INT_PTR* srcEntity, INT_PTR* dstEntity, INT_PTR* context, INT_PTR* pdu, smiOCTETS* msgBufDesc) #uselib "wsnmp32.dll" #cfunc global SnmpDecodeMsg "SnmpDecodeMsg" intptr, intptr, intptr, intptr, intptr, intptr ; res = SnmpDecodeMsg(session, varptr(srcEntity), varptr(dstEntity), varptr(context), varptr(pdu), varptr(msgBufDesc)) ; session : INT_PTR -> "intptr" ; srcEntity : INT_PTR* in/out -> "intptr" ; dstEntity : INT_PTR* in/out -> "intptr" ; context : INT_PTR* in/out -> "intptr" ; pdu : INT_PTR* in/out -> "intptr" ; msgBufDesc : smiOCTETS* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsnmp32 = windows.NewLazySystemDLL("wsnmp32.dll")
procSnmpDecodeMsg = wsnmp32.NewProc("SnmpDecodeMsg")
)
// session (INT_PTR), srcEntity (INT_PTR* in/out), dstEntity (INT_PTR* in/out), context (INT_PTR* in/out), pdu (INT_PTR* in/out), msgBufDesc (smiOCTETS* in/out)
r1, _, err := procSnmpDecodeMsg.Call(
uintptr(session),
uintptr(srcEntity),
uintptr(dstEntity),
uintptr(context),
uintptr(pdu),
uintptr(msgBufDesc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SnmpDecodeMsg(
session: NativeInt; // INT_PTR
srcEntity: Pointer; // INT_PTR* in/out
dstEntity: Pointer; // INT_PTR* in/out
context: Pointer; // INT_PTR* in/out
pdu: Pointer; // INT_PTR* in/out
msgBufDesc: Pointer // smiOCTETS* in/out
): DWORD; stdcall;
external 'wsnmp32.dll' name 'SnmpDecodeMsg';result := DllCall("wsnmp32\SnmpDecodeMsg"
, "Ptr", session ; INT_PTR
, "Ptr", srcEntity ; INT_PTR* in/out
, "Ptr", dstEntity ; INT_PTR* in/out
, "Ptr", context ; INT_PTR* in/out
, "Ptr", pdu ; INT_PTR* in/out
, "Ptr", msgBufDesc ; smiOCTETS* in/out
, "UInt") ; return: DWORD●SnmpDecodeMsg(session, srcEntity, dstEntity, context, pdu, msgBufDesc) = DLL("wsnmp32.dll", "dword SnmpDecodeMsg(int, void*, void*, void*, void*, void*)")
# 呼び出し: SnmpDecodeMsg(session, srcEntity, dstEntity, context, pdu, msgBufDesc)
# session : INT_PTR -> "int"
# srcEntity : INT_PTR* in/out -> "void*"
# dstEntity : INT_PTR* in/out -> "void*"
# context : INT_PTR* in/out -> "void*"
# pdu : INT_PTR* in/out -> "void*"
# msgBufDesc : smiOCTETS* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。