Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › GetApiSetModuleBaseName

GetApiSetModuleBaseName

関数
APIセット契約名から実装モジュールの基底名を取得する。
DLLapi-ms-win-core-apiquery-l2-1-1.dll呼出規約winapi

シグネチャ

// api-ms-win-core-apiquery-l2-1-1.dll
#include <windows.h>

HRESULT GetApiSetModuleBaseName(
    LPCSTR contractName,
    DWORD bufferLength,
    LPWSTR moduleBaseName,
    DWORD* actualNameLength   // optional
);

パラメーター

名前方向説明
contractNameLPCSTRin解決するAPIセットのコントラクト名(ANSI文字列)。
bufferLengthDWORDin出力バッファmoduleBaseNameのサイズ(文字数)。
moduleBaseNameLPWSTRout解決されたモジュールのベース名を受け取るワイド文字列バッファ。
actualNameLengthDWORD*outoptional実際に必要な名前の長さ(文字数)を受け取る出力ポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-core-apiquery-l2-1-1.dll
#include <windows.h>

HRESULT GetApiSetModuleBaseName(
    LPCSTR contractName,
    DWORD bufferLength,
    LPWSTR moduleBaseName,
    DWORD* actualNameLength   // optional
);
[DllImport("api-ms-win-core-apiquery-l2-1-1.dll", ExactSpelling = true)]
static extern int GetApiSetModuleBaseName(
    [MarshalAs(UnmanagedType.LPStr)] string contractName,   // LPCSTR
    uint bufferLength,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder moduleBaseName,   // LPWSTR out
    IntPtr actualNameLength   // DWORD* optional, out
);
<DllImport("api-ms-win-core-apiquery-l2-1-1.dll", ExactSpelling:=True)>
Public Shared Function GetApiSetModuleBaseName(
    <MarshalAs(UnmanagedType.LPStr)> contractName As String,   ' LPCSTR
    bufferLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> moduleBaseName As System.Text.StringBuilder,   ' LPWSTR out
    actualNameLength As IntPtr   ' DWORD* optional, out
) As Integer
End Function
' contractName : LPCSTR
' bufferLength : DWORD
' moduleBaseName : LPWSTR out
' actualNameLength : DWORD* optional, out
Declare PtrSafe Function GetApiSetModuleBaseName Lib "api-ms-win-core-apiquery-l2-1-1" ( _
    ByVal contractName As String, _
    ByVal bufferLength As Long, _
    ByVal moduleBaseName As LongPtr, _
    ByVal actualNameLength As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetApiSetModuleBaseName = ctypes.windll.LoadLibrary("api-ms-win-core-apiquery-l2-1-1.dll").GetApiSetModuleBaseName
GetApiSetModuleBaseName.restype = ctypes.c_int
GetApiSetModuleBaseName.argtypes = [
    wintypes.LPCSTR,  # contractName : LPCSTR
    wintypes.DWORD,  # bufferLength : DWORD
    wintypes.LPWSTR,  # moduleBaseName : LPWSTR out
    ctypes.POINTER(wintypes.DWORD),  # actualNameLength : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-apiquery-l2-1-1.dll')
GetApiSetModuleBaseName = Fiddle::Function.new(
  lib['GetApiSetModuleBaseName'],
  [
    Fiddle::TYPE_VOIDP,  # contractName : LPCSTR
    -Fiddle::TYPE_INT,  # bufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # moduleBaseName : LPWSTR out
    Fiddle::TYPE_VOIDP,  # actualNameLength : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-apiquery-l2-1-1")]
extern "system" {
    fn GetApiSetModuleBaseName(
        contractName: *const u8,  // LPCSTR
        bufferLength: u32,  // DWORD
        moduleBaseName: *mut u16,  // LPWSTR out
        actualNameLength: *mut u32  // DWORD* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-apiquery-l2-1-1.dll")]
public static extern int GetApiSetModuleBaseName([MarshalAs(UnmanagedType.LPStr)] string contractName, uint bufferLength, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder moduleBaseName, IntPtr actualNameLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-apiquery-l2-1-1_GetApiSetModuleBaseName' -Namespace Win32 -PassThru
# $api::GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
#uselib "api-ms-win-core-apiquery-l2-1-1.dll"
#func global GetApiSetModuleBaseName "GetApiSetModuleBaseName" sptr, sptr, sptr, sptr
; GetApiSetModuleBaseName contractName, bufferLength, varptr(moduleBaseName), varptr(actualNameLength)   ; 戻り値は stat
; contractName : LPCSTR -> "sptr"
; bufferLength : DWORD -> "sptr"
; moduleBaseName : LPWSTR out -> "sptr"
; actualNameLength : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-apiquery-l2-1-1.dll"
#cfunc global GetApiSetModuleBaseName "GetApiSetModuleBaseName" str, int, var, var
; res = GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
; contractName : LPCSTR -> "str"
; bufferLength : DWORD -> "int"
; moduleBaseName : LPWSTR out -> "var"
; actualNameLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT GetApiSetModuleBaseName(LPCSTR contractName, DWORD bufferLength, LPWSTR moduleBaseName, DWORD* actualNameLength)
#uselib "api-ms-win-core-apiquery-l2-1-1.dll"
#cfunc global GetApiSetModuleBaseName "GetApiSetModuleBaseName" str, int, var, var
; res = GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
; contractName : LPCSTR -> "str"
; bufferLength : DWORD -> "int"
; moduleBaseName : LPWSTR out -> "var"
; actualNameLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_apiquery_l2_1_1 = windows.NewLazySystemDLL("api-ms-win-core-apiquery-l2-1-1.dll")
	procGetApiSetModuleBaseName = api_ms_win_core_apiquery_l2_1_1.NewProc("GetApiSetModuleBaseName")
)

// contractName (LPCSTR), bufferLength (DWORD), moduleBaseName (LPWSTR out), actualNameLength (DWORD* optional, out)
r1, _, err := procGetApiSetModuleBaseName.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(contractName))),
	uintptr(bufferLength),
	uintptr(moduleBaseName),
	uintptr(actualNameLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetApiSetModuleBaseName(
  contractName: PAnsiChar;   // LPCSTR
  bufferLength: DWORD;   // DWORD
  moduleBaseName: PWideChar;   // LPWSTR out
  actualNameLength: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'api-ms-win-core-apiquery-l2-1-1.dll' name 'GetApiSetModuleBaseName';
result := DllCall("api-ms-win-core-apiquery-l2-1-1\GetApiSetModuleBaseName"
    , "AStr", contractName   ; LPCSTR
    , "UInt", bufferLength   ; DWORD
    , "Ptr", moduleBaseName   ; LPWSTR out
    , "Ptr", actualNameLength   ; DWORD* optional, out
    , "Int")   ; return: HRESULT
●GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength) = DLL("api-ms-win-core-apiquery-l2-1-1.dll", "int GetApiSetModuleBaseName(char*, dword, char*, void*)")
# 呼び出し: GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
# contractName : LPCSTR -> "char*"
# bufferLength : DWORD -> "dword"
# moduleBaseName : LPWSTR out -> "char*"
# actualNameLength : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "api-ms-win-core-apiquery-l2-1-1" fn GetApiSetModuleBaseName(
    contractName: [*c]const u8, // LPCSTR
    bufferLength: u32, // DWORD
    moduleBaseName: [*c]u16, // LPWSTR out
    actualNameLength: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc GetApiSetModuleBaseName(
    contractName: cstring,  # LPCSTR
    bufferLength: uint32,  # DWORD
    moduleBaseName: ptr uint16,  # LPWSTR out
    actualNameLength: ptr uint32  # DWORD* optional, out
): int32 {.importc: "GetApiSetModuleBaseName", stdcall, dynlib: "api-ms-win-core-apiquery-l2-1-1.dll".}
pragma(lib, "api-ms-win-core-apiquery-l2-1-1");
extern(Windows)
int GetApiSetModuleBaseName(
    const(char)* contractName,   // LPCSTR
    uint bufferLength,   // DWORD
    wchar* moduleBaseName,   // LPWSTR out
    uint* actualNameLength   // DWORD* optional, out
);
ccall((:GetApiSetModuleBaseName, "api-ms-win-core-apiquery-l2-1-1.dll"), stdcall, Int32,
      (Cstring, UInt32, Ptr{UInt16}, Ptr{UInt32}),
      contractName, bufferLength, moduleBaseName, actualNameLength)
# contractName : LPCSTR -> Cstring
# bufferLength : DWORD -> UInt32
# moduleBaseName : LPWSTR out -> Ptr{UInt16}
# actualNameLength : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetApiSetModuleBaseName(
    const char* contractName,
    uint32_t bufferLength,
    uint16_t* moduleBaseName,
    uint32_t* actualNameLength);
]]
local api-ms-win-core-apiquery-l2-1-1 = ffi.load("api-ms-win-core-apiquery-l2-1-1")
-- api-ms-win-core-apiquery-l2-1-1.GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
-- contractName : LPCSTR
-- bufferLength : DWORD
-- moduleBaseName : LPWSTR out
-- actualNameLength : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-apiquery-l2-1-1.dll');
const GetApiSetModuleBaseName = lib.func('__stdcall', 'GetApiSetModuleBaseName', 'int32_t', ['str', 'uint32_t', 'uint16_t *', 'uint32_t *']);
// GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
// contractName : LPCSTR -> 'str'
// bufferLength : DWORD -> 'uint32_t'
// moduleBaseName : LPWSTR out -> 'uint16_t *'
// actualNameLength : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-core-apiquery-l2-1-1.dll", {
  GetApiSetModuleBaseName: { parameters: ["buffer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength)
// contractName : LPCSTR -> "buffer"
// bufferLength : DWORD -> "u32"
// moduleBaseName : LPWSTR out -> "buffer"
// actualNameLength : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetApiSetModuleBaseName(
    const char* contractName,
    uint32_t bufferLength,
    uint16_t* moduleBaseName,
    uint32_t* actualNameLength);
C, "api-ms-win-core-apiquery-l2-1-1.dll");
// $ffi->GetApiSetModuleBaseName(contractName, bufferLength, moduleBaseName, actualNameLength);
// contractName : LPCSTR
// bufferLength : DWORD
// moduleBaseName : LPWSTR out
// actualNameLength : DWORD* 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 Api-ms-win-core-apiquery-l2-1-1 extends StdCallLibrary {
    Api-ms-win-core-apiquery-l2-1-1 INSTANCE = Native.load("api-ms-win-core-apiquery-l2-1-1", Api-ms-win-core-apiquery-l2-1-1.class);
    int GetApiSetModuleBaseName(
        String contractName,   // LPCSTR
        int bufferLength,   // DWORD
        char[] moduleBaseName,   // LPWSTR out
        IntByReference actualNameLength   // DWORD* optional, out
    );
}
@[Link("api-ms-win-core-apiquery-l2-1-1")]
lib Libapi-ms-win-core-apiquery-l2-1-1
  fun GetApiSetModuleBaseName = GetApiSetModuleBaseName(
    contractName : UInt8*,   # LPCSTR
    bufferLength : UInt32,   # DWORD
    moduleBaseName : UInt16*,   # LPWSTR out
    actualNameLength : UInt32*   # DWORD* 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 GetApiSetModuleBaseNameNative = Int32 Function(Pointer<Utf8>, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef GetApiSetModuleBaseNameDart = int Function(Pointer<Utf8>, int, Pointer<Utf16>, Pointer<Uint32>);
final GetApiSetModuleBaseName = DynamicLibrary.open('api-ms-win-core-apiquery-l2-1-1.dll')
    .lookupFunction<GetApiSetModuleBaseNameNative, GetApiSetModuleBaseNameDart>('GetApiSetModuleBaseName');
// contractName : LPCSTR -> Pointer<Utf8>
// bufferLength : DWORD -> Uint32
// moduleBaseName : LPWSTR out -> Pointer<Utf16>
// actualNameLength : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetApiSetModuleBaseName(
  contractName: PAnsiChar;   // LPCSTR
  bufferLength: DWORD;   // DWORD
  moduleBaseName: PWideChar;   // LPWSTR out
  actualNameLength: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'api-ms-win-core-apiquery-l2-1-1.dll' name 'GetApiSetModuleBaseName';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetApiSetModuleBaseName"
  c_GetApiSetModuleBaseName :: CString -> Word32 -> CWString -> Ptr Word32 -> IO Int32
-- contractName : LPCSTR -> CString
-- bufferLength : DWORD -> Word32
-- moduleBaseName : LPWSTR out -> CWString
-- actualNameLength : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getapisetmodulebasename =
  foreign "GetApiSetModuleBaseName"
    (string @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* contractName : LPCSTR -> string *)
(* bufferLength : DWORD -> uint32_t *)
(* moduleBaseName : LPWSTR out -> (ptr uint16_t) *)
(* actualNameLength : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-core-apiquery-l2-1-1 (t "api-ms-win-core-apiquery-l2-1-1.dll"))
(cffi:use-foreign-library api-ms-win-core-apiquery-l2-1-1)

(cffi:defcfun ("GetApiSetModuleBaseName" get-api-set-module-base-name :convention :stdcall) :int32
  (contract-name :string)   ; LPCSTR
  (buffer-length :uint32)   ; DWORD
  (module-base-name :pointer)   ; LPWSTR out
  (actual-name-length :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetApiSetModuleBaseName = Win32::API::More->new('api-ms-win-core-apiquery-l2-1-1',
    'int GetApiSetModuleBaseName(LPCSTR contractName, DWORD bufferLength, LPWSTR moduleBaseName, LPVOID actualNameLength)');
# my $ret = $GetApiSetModuleBaseName->Call($contractName, $bufferLength, $moduleBaseName, $actualNameLength);
# contractName : LPCSTR -> LPCSTR
# bufferLength : DWORD -> DWORD
# moduleBaseName : LPWSTR out -> LPWSTR
# actualNameLength : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。