ホーム › NetworkManagement.Snmp › SnmpMgrOidToStr
SnmpMgrOidToStr
関数SNMPのOIDをドット区切りの文字列に変換する。
シグネチャ
// mgmtapi.dll
#include <windows.h>
BOOL SnmpMgrOidToStr(
AsnObjectIdentifier* oid,
LPSTR* string // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| oid | AsnObjectIdentifier* | inout | 文字列化するOID構造体ポインタ。 |
| string | LPSTR* | outoptional | 確保した文字列バッファへのポインタを受け取る出力先。SnmpUtilMemFreeで解放する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// mgmtapi.dll
#include <windows.h>
BOOL SnmpMgrOidToStr(
AsnObjectIdentifier* oid,
LPSTR* string // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mgmtapi.dll", ExactSpelling = true)]
static extern bool SnmpMgrOidToStr(
IntPtr oid, // AsnObjectIdentifier* in/out
IntPtr string // LPSTR* optional, out
);<DllImport("mgmtapi.dll", ExactSpelling:=True)>
Public Shared Function SnmpMgrOidToStr(
oid As IntPtr, ' AsnObjectIdentifier* in/out
[string] As IntPtr ' LPSTR* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' oid : AsnObjectIdentifier* in/out
' string : LPSTR* optional, out
Declare PtrSafe Function SnmpMgrOidToStr Lib "mgmtapi" ( _
ByVal oid As LongPtr, _
ByVal string As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SnmpMgrOidToStr = ctypes.windll.mgmtapi.SnmpMgrOidToStr
SnmpMgrOidToStr.restype = wintypes.BOOL
SnmpMgrOidToStr.argtypes = [
ctypes.c_void_p, # oid : AsnObjectIdentifier* in/out
ctypes.c_void_p, # string : LPSTR* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mgmtapi.dll')
SnmpMgrOidToStr = Fiddle::Function.new(
lib['SnmpMgrOidToStr'],
[
Fiddle::TYPE_VOIDP, # oid : AsnObjectIdentifier* in/out
Fiddle::TYPE_VOIDP, # string : LPSTR* optional, out
],
Fiddle::TYPE_INT)#[link(name = "mgmtapi")]
extern "system" {
fn SnmpMgrOidToStr(
oid: *mut AsnObjectIdentifier, // AsnObjectIdentifier* in/out
string: *mut *mut u8 // LPSTR* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mgmtapi.dll")]
public static extern bool SnmpMgrOidToStr(IntPtr oid, IntPtr string);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mgmtapi_SnmpMgrOidToStr' -Namespace Win32 -PassThru
# $api::SnmpMgrOidToStr(oid, string)#uselib "mgmtapi.dll"
#func global SnmpMgrOidToStr "SnmpMgrOidToStr" sptr, sptr
; SnmpMgrOidToStr varptr(oid), varptr(string) ; 戻り値は stat
; oid : AsnObjectIdentifier* in/out -> "sptr"
; string : LPSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mgmtapi.dll" #cfunc global SnmpMgrOidToStr "SnmpMgrOidToStr" var, var ; res = SnmpMgrOidToStr(oid, string) ; oid : AsnObjectIdentifier* in/out -> "var" ; string : LPSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mgmtapi.dll" #cfunc global SnmpMgrOidToStr "SnmpMgrOidToStr" sptr, sptr ; res = SnmpMgrOidToStr(varptr(oid), varptr(string)) ; oid : AsnObjectIdentifier* in/out -> "sptr" ; string : LPSTR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SnmpMgrOidToStr(AsnObjectIdentifier* oid, LPSTR* string) #uselib "mgmtapi.dll" #cfunc global SnmpMgrOidToStr "SnmpMgrOidToStr" var, var ; res = SnmpMgrOidToStr(oid, string) ; oid : AsnObjectIdentifier* in/out -> "var" ; string : LPSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SnmpMgrOidToStr(AsnObjectIdentifier* oid, LPSTR* string) #uselib "mgmtapi.dll" #cfunc global SnmpMgrOidToStr "SnmpMgrOidToStr" intptr, intptr ; res = SnmpMgrOidToStr(varptr(oid), varptr(string)) ; oid : AsnObjectIdentifier* in/out -> "intptr" ; string : LPSTR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mgmtapi = windows.NewLazySystemDLL("mgmtapi.dll")
procSnmpMgrOidToStr = mgmtapi.NewProc("SnmpMgrOidToStr")
)
// oid (AsnObjectIdentifier* in/out), string (LPSTR* optional, out)
r1, _, err := procSnmpMgrOidToStr.Call(
uintptr(oid),
uintptr(string),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SnmpMgrOidToStr(
oid: Pointer; // AsnObjectIdentifier* in/out
string: PPAnsiChar // LPSTR* optional, out
): BOOL; stdcall;
external 'mgmtapi.dll' name 'SnmpMgrOidToStr';result := DllCall("mgmtapi\SnmpMgrOidToStr"
, "Ptr", oid ; AsnObjectIdentifier* in/out
, "Ptr", string ; LPSTR* optional, out
, "Int") ; return: BOOL●SnmpMgrOidToStr(oid, string) = DLL("mgmtapi.dll", "bool SnmpMgrOidToStr(void*, void*)")
# 呼び出し: SnmpMgrOidToStr(oid, string)
# oid : AsnObjectIdentifier* in/out -> "void*"
# string : LPSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mgmtapi" fn SnmpMgrOidToStr(
oid: [*c]AsnObjectIdentifier, // AsnObjectIdentifier* in/out
string: [*c][*c]u8 // LPSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc SnmpMgrOidToStr(
oid: ptr AsnObjectIdentifier, # AsnObjectIdentifier* in/out
string: ptr cstring # LPSTR* optional, out
): int32 {.importc: "SnmpMgrOidToStr", stdcall, dynlib: "mgmtapi.dll".}pragma(lib, "mgmtapi");
extern(Windows)
int SnmpMgrOidToStr(
AsnObjectIdentifier* oid, // AsnObjectIdentifier* in/out
char** string // LPSTR* optional, out
);ccall((:SnmpMgrOidToStr, "mgmtapi.dll"), stdcall, Int32,
(Ptr{AsnObjectIdentifier}, Ptr{Ptr{UInt8}}),
oid, string)
# oid : AsnObjectIdentifier* in/out -> Ptr{AsnObjectIdentifier}
# string : LPSTR* optional, out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SnmpMgrOidToStr(
void* oid,
char** string);
]]
local mgmtapi = ffi.load("mgmtapi")
-- mgmtapi.SnmpMgrOidToStr(oid, string)
-- oid : AsnObjectIdentifier* in/out
-- string : LPSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mgmtapi.dll');
const SnmpMgrOidToStr = lib.func('__stdcall', 'SnmpMgrOidToStr', 'int32_t', ['void *', 'void *']);
// SnmpMgrOidToStr(oid, string)
// oid : AsnObjectIdentifier* in/out -> 'void *'
// string : LPSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mgmtapi.dll", {
SnmpMgrOidToStr: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.SnmpMgrOidToStr(oid, string)
// oid : AsnObjectIdentifier* in/out -> "pointer"
// string : LPSTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SnmpMgrOidToStr(
void* oid,
char** string);
C, "mgmtapi.dll");
// $ffi->SnmpMgrOidToStr(oid, string);
// oid : AsnObjectIdentifier* in/out
// string : LPSTR* optional, 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 Mgmtapi extends StdCallLibrary {
Mgmtapi INSTANCE = Native.load("mgmtapi", Mgmtapi.class);
boolean SnmpMgrOidToStr(
Pointer oid, // AsnObjectIdentifier* in/out
PointerByReference string // LPSTR* optional, out
);
}@[Link("mgmtapi")]
lib Libmgmtapi
fun SnmpMgrOidToStr = SnmpMgrOidToStr(
oid : AsnObjectIdentifier*, # AsnObjectIdentifier* in/out
string : UInt8** # LPSTR* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SnmpMgrOidToStrNative = Int32 Function(Pointer<Void>, Pointer<Pointer<Utf8>>);
typedef SnmpMgrOidToStrDart = int Function(Pointer<Void>, Pointer<Pointer<Utf8>>);
final SnmpMgrOidToStr = DynamicLibrary.open('mgmtapi.dll')
.lookupFunction<SnmpMgrOidToStrNative, SnmpMgrOidToStrDart>('SnmpMgrOidToStr');
// oid : AsnObjectIdentifier* in/out -> Pointer<Void>
// string : LPSTR* optional, out -> Pointer<Pointer<Utf8>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SnmpMgrOidToStr(
oid: Pointer; // AsnObjectIdentifier* in/out
string: PPAnsiChar // LPSTR* optional, out
): BOOL; stdcall;
external 'mgmtapi.dll' name 'SnmpMgrOidToStr';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SnmpMgrOidToStr"
c_SnmpMgrOidToStr :: Ptr () -> Ptr CString -> IO CInt
-- oid : AsnObjectIdentifier* in/out -> Ptr ()
-- string : LPSTR* optional, out -> Ptr CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let snmpmgroidtostr =
foreign "SnmpMgrOidToStr"
((ptr void) @-> (ptr string) @-> returning int32_t)
(* oid : AsnObjectIdentifier* in/out -> (ptr void) *)
(* string : LPSTR* optional, out -> (ptr string) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mgmtapi (t "mgmtapi.dll"))
(cffi:use-foreign-library mgmtapi)
(cffi:defcfun ("SnmpMgrOidToStr" snmp-mgr-oid-to-str :convention :stdcall) :int32
(oid :pointer) ; AsnObjectIdentifier* in/out
(string :pointer)) ; LPSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SnmpMgrOidToStr = Win32::API::More->new('mgmtapi',
'BOOL SnmpMgrOidToStr(LPVOID oid, LPVOID string)');
# my $ret = $SnmpMgrOidToStr->Call($oid, $string);
# oid : AsnObjectIdentifier* in/out -> LPVOID
# string : LPSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。