ホーム › NetworkManagement.Snmp › SnmpCreateSession
SnmpCreateSession
関数コールバックを伴うWinSNMPセッションを作成する。
シグネチャ
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpCreateSession(
HWND hWnd,
DWORD wMsg,
SNMPAPI_CALLBACK fCallBack,
void* lpClientData
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | 通知メッセージ送信先のウィンドウハンドル。コールバック使用時はNULL可。 |
| wMsg | DWORD | in | 通知に使用するウィンドウメッセージID。 |
| fCallBack | SNMPAPI_CALLBACK | in | メッセージの代わりに呼び出すコールバック関数(SNMPAPI_CALLBACK)。不要ならNULL。 |
| lpClientData | void* | inout | コールバックへ渡す任意のクライアントデータポインタ。 |
戻り値の型: INT_PTR
各言語での呼び出し定義
// wsnmp32.dll
#include <windows.h>
INT_PTR SnmpCreateSession(
HWND hWnd,
DWORD wMsg,
SNMPAPI_CALLBACK fCallBack,
void* lpClientData
);[DllImport("wsnmp32.dll", ExactSpelling = true)]
static extern IntPtr SnmpCreateSession(
IntPtr hWnd, // HWND
uint wMsg, // DWORD
IntPtr fCallBack, // SNMPAPI_CALLBACK
IntPtr lpClientData // void* in/out
);<DllImport("wsnmp32.dll", ExactSpelling:=True)>
Public Shared Function SnmpCreateSession(
hWnd As IntPtr, ' HWND
wMsg As UInteger, ' DWORD
fCallBack As IntPtr, ' SNMPAPI_CALLBACK
lpClientData As IntPtr ' void* in/out
) As IntPtr
End Function' hWnd : HWND
' wMsg : DWORD
' fCallBack : SNMPAPI_CALLBACK
' lpClientData : void* in/out
Declare PtrSafe Function SnmpCreateSession Lib "wsnmp32" ( _
ByVal hWnd As LongPtr, _
ByVal wMsg As Long, _
ByVal fCallBack As LongPtr, _
ByVal lpClientData As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpCreateSession = ctypes.windll.wsnmp32.SnmpCreateSession
SnmpCreateSession.restype = ctypes.c_ssize_t
SnmpCreateSession.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.DWORD, # wMsg : DWORD
ctypes.c_void_p, # fCallBack : SNMPAPI_CALLBACK
ctypes.POINTER(None), # lpClientData : void* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('wsnmp32.dll')
SnmpCreateSession = Fiddle::Function.new(
lib['SnmpCreateSession'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
-Fiddle::TYPE_INT, # wMsg : DWORD
Fiddle::TYPE_VOIDP, # fCallBack : SNMPAPI_CALLBACK
Fiddle::TYPE_VOIDP, # lpClientData : void* in/out
],
Fiddle::TYPE_INTPTR_T)#[link(name = "wsnmp32")]
extern "system" {
fn SnmpCreateSession(
hWnd: *mut core::ffi::c_void, // HWND
wMsg: u32, // DWORD
fCallBack: *const core::ffi::c_void, // SNMPAPI_CALLBACK
lpClientData: *mut () // void* in/out
) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("wsnmp32.dll")]
public static extern IntPtr SnmpCreateSession(IntPtr hWnd, uint wMsg, IntPtr fCallBack, IntPtr lpClientData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wsnmp32_SnmpCreateSession' -Namespace Win32 -PassThru
# $api::SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)#uselib "wsnmp32.dll"
#func global SnmpCreateSession "SnmpCreateSession" sptr, sptr, sptr, sptr
; SnmpCreateSession hWnd, wMsg, fCallBack, lpClientData ; 戻り値は stat
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "sptr"
; fCallBack : SNMPAPI_CALLBACK -> "sptr"
; lpClientData : void* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "wsnmp32.dll"
#cfunc global SnmpCreateSession "SnmpCreateSession" sptr, int, sptr, sptr
; res = SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "int"
; fCallBack : SNMPAPI_CALLBACK -> "sptr"
; lpClientData : void* in/out -> "sptr"; INT_PTR SnmpCreateSession(HWND hWnd, DWORD wMsg, SNMPAPI_CALLBACK fCallBack, void* lpClientData)
#uselib "wsnmp32.dll"
#cfunc global SnmpCreateSession "SnmpCreateSession" intptr, int, intptr, intptr
; res = SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
; hWnd : HWND -> "intptr"
; wMsg : DWORD -> "int"
; fCallBack : SNMPAPI_CALLBACK -> "intptr"
; lpClientData : void* in/out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsnmp32 = windows.NewLazySystemDLL("wsnmp32.dll")
procSnmpCreateSession = wsnmp32.NewProc("SnmpCreateSession")
)
// hWnd (HWND), wMsg (DWORD), fCallBack (SNMPAPI_CALLBACK), lpClientData (void* in/out)
r1, _, err := procSnmpCreateSession.Call(
uintptr(hWnd),
uintptr(wMsg),
uintptr(fCallBack),
uintptr(lpClientData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INT_PTRfunction SnmpCreateSession(
hWnd: THandle; // HWND
wMsg: DWORD; // DWORD
fCallBack: Pointer; // SNMPAPI_CALLBACK
lpClientData: Pointer // void* in/out
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpCreateSession';result := DllCall("wsnmp32\SnmpCreateSession"
, "Ptr", hWnd ; HWND
, "UInt", wMsg ; DWORD
, "Ptr", fCallBack ; SNMPAPI_CALLBACK
, "Ptr", lpClientData ; void* in/out
, "Ptr") ; return: INT_PTR●SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData) = DLL("wsnmp32.dll", "int SnmpCreateSession(void*, dword, void*, void*)")
# 呼び出し: SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
# hWnd : HWND -> "void*"
# wMsg : DWORD -> "dword"
# fCallBack : SNMPAPI_CALLBACK -> "void*"
# lpClientData : void* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wsnmp32" fn SnmpCreateSession(
hWnd: ?*anyopaque, // HWND
wMsg: u32, // DWORD
fCallBack: ?*anyopaque, // SNMPAPI_CALLBACK
lpClientData: ?*anyopaque // void* in/out
) callconv(std.os.windows.WINAPI) isize;proc SnmpCreateSession(
hWnd: pointer, # HWND
wMsg: uint32, # DWORD
fCallBack: pointer, # SNMPAPI_CALLBACK
lpClientData: pointer # void* in/out
): int {.importc: "SnmpCreateSession", stdcall, dynlib: "wsnmp32.dll".}pragma(lib, "wsnmp32");
extern(Windows)
ptrdiff_t SnmpCreateSession(
void* hWnd, // HWND
uint wMsg, // DWORD
void* fCallBack, // SNMPAPI_CALLBACK
void* lpClientData // void* in/out
);ccall((:SnmpCreateSession, "wsnmp32.dll"), stdcall, Int,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
hWnd, wMsg, fCallBack, lpClientData)
# hWnd : HWND -> Ptr{Cvoid}
# wMsg : DWORD -> UInt32
# fCallBack : SNMPAPI_CALLBACK -> Ptr{Cvoid}
# lpClientData : void* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
intptr_t SnmpCreateSession(
void* hWnd,
uint32_t wMsg,
void* fCallBack,
void* lpClientData);
]]
local wsnmp32 = ffi.load("wsnmp32")
-- wsnmp32.SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
-- hWnd : HWND
-- wMsg : DWORD
-- fCallBack : SNMPAPI_CALLBACK
-- lpClientData : void* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('wsnmp32.dll');
const SnmpCreateSession = lib.func('__stdcall', 'SnmpCreateSession', 'intptr_t', ['void *', 'uint32_t', 'void *', 'void *']);
// SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
// hWnd : HWND -> 'void *'
// wMsg : DWORD -> 'uint32_t'
// fCallBack : SNMPAPI_CALLBACK -> 'void *'
// lpClientData : void* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("wsnmp32.dll", {
SnmpCreateSession: { parameters: ["pointer", "u32", "pointer", "pointer"], result: "isize" },
});
// lib.symbols.SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData)
// hWnd : HWND -> "pointer"
// wMsg : DWORD -> "u32"
// fCallBack : SNMPAPI_CALLBACK -> "pointer"
// lpClientData : void* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
intptr_t SnmpCreateSession(
void* hWnd,
uint32_t wMsg,
void* fCallBack,
void* lpClientData);
C, "wsnmp32.dll");
// $ffi->SnmpCreateSession(hWnd, wMsg, fCallBack, lpClientData);
// hWnd : HWND
// wMsg : DWORD
// fCallBack : SNMPAPI_CALLBACK
// lpClientData : void* 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 SnmpCreateSession(
Pointer hWnd, // HWND
int wMsg, // DWORD
Callback fCallBack, // SNMPAPI_CALLBACK
Pointer lpClientData // void* in/out
);
}@[Link("wsnmp32")]
lib Libwsnmp32
fun SnmpCreateSession = SnmpCreateSession(
hWnd : Void*, # HWND
wMsg : UInt32, # DWORD
fCallBack : Void*, # SNMPAPI_CALLBACK
lpClientData : Void* # void* 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 SnmpCreateSessionNative = IntPtr Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef SnmpCreateSessionDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final SnmpCreateSession = DynamicLibrary.open('wsnmp32.dll')
.lookupFunction<SnmpCreateSessionNative, SnmpCreateSessionDart>('SnmpCreateSession');
// hWnd : HWND -> Pointer<Void>
// wMsg : DWORD -> Uint32
// fCallBack : SNMPAPI_CALLBACK -> Pointer<Void>
// lpClientData : void* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SnmpCreateSession(
hWnd: THandle; // HWND
wMsg: DWORD; // DWORD
fCallBack: Pointer; // SNMPAPI_CALLBACK
lpClientData: Pointer // void* in/out
): NativeInt; stdcall;
external 'wsnmp32.dll' name 'SnmpCreateSession';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SnmpCreateSession"
c_SnmpCreateSession :: Ptr () -> Word32 -> Ptr () -> Ptr () -> IO CIntPtr
-- hWnd : HWND -> Ptr ()
-- wMsg : DWORD -> Word32
-- fCallBack : SNMPAPI_CALLBACK -> Ptr ()
-- lpClientData : void* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let snmpcreatesession =
foreign "SnmpCreateSession"
((ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning intptr_t)
(* hWnd : HWND -> (ptr void) *)
(* wMsg : DWORD -> uint32_t *)
(* fCallBack : SNMPAPI_CALLBACK -> (ptr void) *)
(* lpClientData : void* 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 ("SnmpCreateSession" snmp-create-session :convention :stdcall) :int64
(h-wnd :pointer) ; HWND
(w-msg :uint32) ; DWORD
(f-call-back :pointer) ; SNMPAPI_CALLBACK
(lp-client-data :pointer)) ; void* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SnmpCreateSession = Win32::API::More->new('wsnmp32',
'LPARAM SnmpCreateSession(HANDLE hWnd, DWORD wMsg, LPVOID fCallBack, LPVOID lpClientData)');
# my $ret = $SnmpCreateSession->Call($hWnd, $wMsg, $fCallBack, $lpClientData);
# hWnd : HWND -> HANDLE
# wMsg : DWORD -> DWORD
# fCallBack : SNMPAPI_CALLBACK -> LPVOID
# lpClientData : void* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
使用する型