SnmpOpen
関数シグネチャ
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpOpen(
HWND hWnd,
DWORD wMsg
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | 非同期要求が完了したとき、またはトラップ通知が発生したときに通知する、WinSNMP アプリケーションのウィンドウへのハンドル。 |
| wMsg | DWORD | in | WinSNMP アプリケーションのウィンドウに送信する通知メッセージを識別する符号なし整数を指定します。 |
戻り値の型: INT_PTR
公式ドキュメント
SnmpOpen 関数は、WinSNMP アプリケーションのためにセッションを開くよう Microsoft WinSNMP 実装に要求します。
戻り値
関数が成功した場合、戻り値は、呼び出し元アプリケーションのために実装が開いた WinSNMP セッションを識別するハンドルです。
関数が失敗した場合、戻り値は SNMPAPI_FAILURE です。拡張エラー情報を取得するには、session パラメーターに NULL を指定して SnmpGetLastError を呼び出します。 SnmpGetLastError 関数は、次のいずれかのエラーを返すことがあります。
| 戻り値 | 説明 |
|---|---|
|
SnmpStartup 関数が正常に完了しませんでした。 |
|
| メモリの割り当て中にエラーが発生しました。 | |
| hWnd パラメーターが有効なウィンドウハンドルではありません。 | |
| 不明または未定義のエラーが発生しました。 |
解説(Remarks)
SnmpOpen 関数は、呼び出し元の WinSNMP アプリケーション内で開かれた各 WinSNMP セッションに対して一意のハンドルを返します。アプリケーションは、実装によるリソースの割り当てと解放を容易にするため、 SnmpOpen が返すセッションハンドルを他の WinSNMP 関数の呼び出しで使用する必要があります。実装が個々のセッションにリソースを割り当てている場合、そのセッションに対する SnmpClose の呼び出しに応じて、リソースを順序立てて解放します。
SnmpOpen 関数は、アプリケーションウィンドウのハンドルと通知メッセージ識別子を実装に渡します。wMsg パラメーターで指定された通知メッセージの wParam 要素が 0 の場合、WinSNMP アプリケーションは受信したプロトコルデータユニット (PDU) を取得する必要があります。アプリケーションは、 SnmpOpen が返したセッションハンドルを指定して SnmpRecvMsg 関数を呼び出すことで、これを行います。通知メッセージの wParam パラメーターが 0 以外の場合、それは WinSNMP のエラーコードを表します。このエラーコードは、通知メッセージの lParam パラメーターに含まれる要求識別子によって識別される PDU に適用されます。
1 つの WinSNMP アプリケーションは、複数の WinSNMP セッションを開くことができます。同じウィンドウハンドルを使用して複数のセッションを開く場合、WinSNMP アプリケーションはセッションごとに一意の wMsg パラメーターを指定することをお勧めします。
WinSNMP アプリケーションは、 SnmpOpen 関数の呼び出しによって実装が開いた各セッションに対して、 SnmpClose 関数を 1 回ずつ呼び出すことをお勧めします。WinSNMP アプリケーションが予期せず終了する場合は、実装がすべてのリソースを解放できるように、終了前に SnmpCleanup を呼び出す必要があります。実装は、1 回の SnmpCleanup 呼び出しを、 SnmpOpen の呼び出しによって実装が開いた各セッションに対する一連の SnmpClose 呼び出しと同様に扱います。
WinSNMP セッションを開く方法、および利用可能な SNMP メッセージや非同期イベントをセッションに通知する方法の指定については、 SnmpCreateSession を参照してください。 SnmpCreateSession を呼び出す際には、セッションへの通知としてウィンドウ通知メッセージまたは SNMPAPI_CALLBACK 関数を指定できます。
詳細については、 WinSNMP Sessions を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpOpen(
HWND hWnd,
DWORD wMsg
);[DllImport("wsnmp32.dll", ExactSpelling = true)]
static extern IntPtr SnmpOpen(
IntPtr hWnd, // HWND
uint wMsg // DWORD
);<DllImport("wsnmp32.dll", ExactSpelling:=True)>
Public Shared Function SnmpOpen(
hWnd As IntPtr, ' HWND
wMsg As UInteger ' DWORD
) As IntPtr
End Function' hWnd : HWND
' wMsg : DWORD
Declare PtrSafe Function SnmpOpen Lib "wsnmp32" ( _
ByVal hWnd As LongPtr, _
ByVal wMsg As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpOpen = ctypes.windll.wsnmp32.SnmpOpen
SnmpOpen.restype = ctypes.c_ssize_t
SnmpOpen.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.DWORD, # wMsg : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('wsnmp32.dll')
SnmpOpen = Fiddle::Function.new(
lib['SnmpOpen'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
-Fiddle::TYPE_INT, # wMsg : DWORD
],
Fiddle::TYPE_INTPTR_T)#[link(name = "wsnmp32")]
extern "system" {
fn SnmpOpen(
hWnd: *mut core::ffi::c_void, // HWND
wMsg: u32 // DWORD
) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("wsnmp32.dll")]
public static extern IntPtr SnmpOpen(IntPtr hWnd, uint wMsg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wsnmp32_SnmpOpen' -Namespace Win32 -PassThru
# $api::SnmpOpen(hWnd, wMsg)#uselib "wsnmp32.dll"
#func global SnmpOpen "SnmpOpen" sptr, sptr
; SnmpOpen hWnd, wMsg ; 戻り値は stat
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "wsnmp32.dll"
#cfunc global SnmpOpen "SnmpOpen" sptr, int
; res = SnmpOpen(hWnd, wMsg)
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "int"; INT_PTR SnmpOpen(HWND hWnd, DWORD wMsg)
#uselib "wsnmp32.dll"
#cfunc global SnmpOpen "SnmpOpen" intptr, int
; res = SnmpOpen(hWnd, wMsg)
; hWnd : HWND -> "intptr"
; wMsg : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsnmp32 = windows.NewLazySystemDLL("wsnmp32.dll")
procSnmpOpen = wsnmp32.NewProc("SnmpOpen")
)
// hWnd (HWND), wMsg (DWORD)
r1, _, err := procSnmpOpen.Call(
uintptr(hWnd),
uintptr(wMsg),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INT_PTRfunction SnmpOpen(
hWnd: THandle; // HWND
wMsg: DWORD // DWORD
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpOpen';result := DllCall("wsnmp32\SnmpOpen"
, "Ptr", hWnd ; HWND
, "UInt", wMsg ; DWORD
, "Ptr") ; return: INT_PTR●SnmpOpen(hWnd, wMsg) = DLL("wsnmp32.dll", "int SnmpOpen(void*, dword)")
# 呼び出し: SnmpOpen(hWnd, wMsg)
# hWnd : HWND -> "void*"
# wMsg : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wsnmp32" fn SnmpOpen(
hWnd: ?*anyopaque, // HWND
wMsg: u32 // DWORD
) callconv(std.os.windows.WINAPI) isize;proc SnmpOpen(
hWnd: pointer, # HWND
wMsg: uint32 # DWORD
): int {.importc: "SnmpOpen", stdcall, dynlib: "wsnmp32.dll".}pragma(lib, "wsnmp32");
extern(Windows)
ptrdiff_t SnmpOpen(
void* hWnd, // HWND
uint wMsg // DWORD
);ccall((:SnmpOpen, "wsnmp32.dll"), stdcall, Int,
(Ptr{Cvoid}, UInt32),
hWnd, wMsg)
# hWnd : HWND -> Ptr{Cvoid}
# wMsg : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t SnmpOpen(
void* hWnd,
uint32_t wMsg);
]]
local wsnmp32 = ffi.load("wsnmp32")
-- wsnmp32.SnmpOpen(hWnd, wMsg)
-- hWnd : HWND
-- wMsg : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('wsnmp32.dll');
const SnmpOpen = lib.func('__stdcall', 'SnmpOpen', 'intptr_t', ['void *', 'uint32_t']);
// SnmpOpen(hWnd, wMsg)
// hWnd : HWND -> 'void *'
// wMsg : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("wsnmp32.dll", {
SnmpOpen: { parameters: ["pointer", "u32"], result: "isize" },
});
// lib.symbols.SnmpOpen(hWnd, wMsg)
// hWnd : HWND -> "pointer"
// wMsg : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t SnmpOpen(
void* hWnd,
uint32_t wMsg);
C, "wsnmp32.dll");
// $ffi->SnmpOpen(hWnd, wMsg);
// hWnd : HWND
// wMsg : DWORD
// 構造体/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 SnmpOpen(
Pointer hWnd, // HWND
int wMsg // DWORD
);
}@[Link("wsnmp32")]
lib Libwsnmp32
fun SnmpOpen = SnmpOpen(
hWnd : Void*, # HWND
wMsg : UInt32 # DWORD
) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SnmpOpenNative = IntPtr Function(Pointer<Void>, Uint32);
typedef SnmpOpenDart = int Function(Pointer<Void>, int);
final SnmpOpen = DynamicLibrary.open('wsnmp32.dll')
.lookupFunction<SnmpOpenNative, SnmpOpenDart>('SnmpOpen');
// hWnd : HWND -> Pointer<Void>
// wMsg : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SnmpOpen(
hWnd: THandle; // HWND
wMsg: DWORD // DWORD
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpOpen';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SnmpOpen"
c_SnmpOpen :: Ptr () -> Word32 -> IO CIntPtr
-- hWnd : HWND -> Ptr ()
-- wMsg : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let snmpopen =
foreign "SnmpOpen"
((ptr void) @-> uint32_t @-> returning intptr_t)
(* hWnd : HWND -> (ptr void) *)
(* wMsg : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wsnmp32 (t "wsnmp32.dll"))
(cffi:use-foreign-library wsnmp32)
(cffi:defcfun ("SnmpOpen" snmp-open :convention :stdcall) :int64
(h-wnd :pointer) ; HWND
(w-msg :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SnmpOpen = Win32::API::More->new('wsnmp32',
'LPARAM SnmpOpen(HANDLE hWnd, DWORD wMsg)');
# my $ret = $SnmpOpen->Call($hWnd, $wMsg);
# hWnd : HWND -> HANDLE
# wMsg : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- c SNMPAPI_CALLBACK
- f SnmpCleanup — WinSNMP APIを終了しリソースを解放する。
- f SnmpClose — WinSNMPセッションを閉じて関連リソースを解放する。
- f SnmpCreateSession — コールバックを伴うWinSNMPセッションを作成する。
- f SnmpRecvMsg — WinSNMPセッションで受信したメッセージを取り出す。