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

SnmpMgrOpen

関数
SNMPエージェントへの管理セッションを開いて接続する。
DLLmgmtapi.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

void* SnmpMgrOpen(
    LPSTR lpAgentAddress,   // optional
    LPSTR lpAgentCommunity,   // optional
    INT nTimeOut,
    INT nRetries
);

パラメーター

名前方向
lpAgentAddressLPSTRinoptional
lpAgentCommunityLPSTRinoptional
nTimeOutINTin
nRetriesINTin

戻り値の型: void*

各言語での呼び出し定義

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

void* SnmpMgrOpen(
    LPSTR lpAgentAddress,   // optional
    LPSTR lpAgentCommunity,   // optional
    INT nTimeOut,
    INT nRetries
);
[DllImport("mgmtapi.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr SnmpMgrOpen(
    [MarshalAs(UnmanagedType.LPStr)] string lpAgentAddress,   // LPSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpAgentCommunity,   // LPSTR optional
    int nTimeOut,   // INT
    int nRetries   // INT
);
<DllImport("mgmtapi.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SnmpMgrOpen(
    <MarshalAs(UnmanagedType.LPStr)> lpAgentAddress As String,   ' LPSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpAgentCommunity As String,   ' LPSTR optional
    nTimeOut As Integer,   ' INT
    nRetries As Integer   ' INT
) As IntPtr
End Function
' lpAgentAddress : LPSTR optional
' lpAgentCommunity : LPSTR optional
' nTimeOut : INT
' nRetries : INT
Declare PtrSafe Function SnmpMgrOpen Lib "mgmtapi" ( _
    ByVal lpAgentAddress As String, _
    ByVal lpAgentCommunity As String, _
    ByVal nTimeOut As Long, _
    ByVal nRetries As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SnmpMgrOpen = ctypes.windll.mgmtapi.SnmpMgrOpen
SnmpMgrOpen.restype = ctypes.c_void_p
SnmpMgrOpen.argtypes = [
    wintypes.LPCSTR,  # lpAgentAddress : LPSTR optional
    wintypes.LPCSTR,  # lpAgentCommunity : LPSTR optional
    ctypes.c_int,  # nTimeOut : INT
    ctypes.c_int,  # nRetries : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mgmtapi.dll')
SnmpMgrOpen = Fiddle::Function.new(
  lib['SnmpMgrOpen'],
  [
    Fiddle::TYPE_VOIDP,  # lpAgentAddress : LPSTR optional
    Fiddle::TYPE_VOIDP,  # lpAgentCommunity : LPSTR optional
    Fiddle::TYPE_INT,  # nTimeOut : INT
    Fiddle::TYPE_INT,  # nRetries : INT
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "mgmtapi")]
extern "system" {
    fn SnmpMgrOpen(
        lpAgentAddress: *mut u8,  // LPSTR optional
        lpAgentCommunity: *mut u8,  // LPSTR optional
        nTimeOut: i32,  // INT
        nRetries: i32  // INT
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("mgmtapi.dll", SetLastError = true)]
public static extern IntPtr SnmpMgrOpen([MarshalAs(UnmanagedType.LPStr)] string lpAgentAddress, [MarshalAs(UnmanagedType.LPStr)] string lpAgentCommunity, int nTimeOut, int nRetries);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mgmtapi_SnmpMgrOpen' -Namespace Win32 -PassThru
# $api::SnmpMgrOpen(lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries)
#uselib "mgmtapi.dll"
#func global SnmpMgrOpen "SnmpMgrOpen" sptr, sptr, sptr, sptr
; SnmpMgrOpen lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries   ; 戻り値は stat
; lpAgentAddress : LPSTR optional -> "sptr"
; lpAgentCommunity : LPSTR optional -> "sptr"
; nTimeOut : INT -> "sptr"
; nRetries : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "mgmtapi.dll"
#cfunc global SnmpMgrOpen "SnmpMgrOpen" str, str, int, int
; res = SnmpMgrOpen(lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries)
; lpAgentAddress : LPSTR optional -> "str"
; lpAgentCommunity : LPSTR optional -> "str"
; nTimeOut : INT -> "int"
; nRetries : INT -> "int"
; void* SnmpMgrOpen(LPSTR lpAgentAddress, LPSTR lpAgentCommunity, INT nTimeOut, INT nRetries)
#uselib "mgmtapi.dll"
#cfunc global SnmpMgrOpen "SnmpMgrOpen" str, str, int, int
; res = SnmpMgrOpen(lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries)
; lpAgentAddress : LPSTR optional -> "str"
; lpAgentCommunity : LPSTR optional -> "str"
; nTimeOut : INT -> "int"
; nRetries : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mgmtapi = windows.NewLazySystemDLL("mgmtapi.dll")
	procSnmpMgrOpen = mgmtapi.NewProc("SnmpMgrOpen")
)

// lpAgentAddress (LPSTR optional), lpAgentCommunity (LPSTR optional), nTimeOut (INT), nRetries (INT)
r1, _, err := procSnmpMgrOpen.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpAgentAddress))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpAgentCommunity))),
	uintptr(nTimeOut),
	uintptr(nRetries),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function SnmpMgrOpen(
  lpAgentAddress: PAnsiChar;   // LPSTR optional
  lpAgentCommunity: PAnsiChar;   // LPSTR optional
  nTimeOut: Integer;   // INT
  nRetries: Integer   // INT
): Pointer; stdcall;
  external 'mgmtapi.dll' name 'SnmpMgrOpen';
result := DllCall("mgmtapi\SnmpMgrOpen"
    , "AStr", lpAgentAddress   ; LPSTR optional
    , "AStr", lpAgentCommunity   ; LPSTR optional
    , "Int", nTimeOut   ; INT
    , "Int", nRetries   ; INT
    , "Ptr")   ; return: void*
●SnmpMgrOpen(lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries) = DLL("mgmtapi.dll", "void* SnmpMgrOpen(char*, char*, int, int)")
# 呼び出し: SnmpMgrOpen(lpAgentAddress, lpAgentCommunity, nTimeOut, nRetries)
# lpAgentAddress : LPSTR optional -> "char*"
# lpAgentCommunity : LPSTR optional -> "char*"
# nTimeOut : INT -> "int"
# nRetries : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。