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