PathBuildRootA
関数ドライブ番号からルートパス文字列を生成する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
LPSTR PathBuildRootA(
LPSTR pszRoot,
INT iDrive
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszRoot | LPSTR | out | 構築されたルートパスを受け取る文字列へのポインター。このバッファーは少なくとも 4 文字分のサイズが必要です。 |
| iDrive | INT | in | 対象とするドライブ番号を示す int 型の変数。0 から 25 の間である必要があります。 |
戻り値の型: LPSTR
公式ドキュメント
指定されたドライブ番号からルートパスを作成します。(ANSI)
戻り値
型: LPTSTR
構築されたルートパスのアドレスを返します。何らかの理由(たとえば無効なドライブ番号など)で呼び出しが失敗した場合は、szRoot が変更されずに返されます。
解説(Remarks)
メモ
shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして PathBuildRoot を定義しています。エンコード中立のエイリアスを、エンコード中立ではないコードと混在して使用すると、不一致が生じ、コンパイル エラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
LPSTR PathBuildRootA(
LPSTR pszRoot,
INT iDrive
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr PathBuildRootA(
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszRoot, // LPSTR out
int iDrive // INT
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathBuildRootA(
<MarshalAs(UnmanagedType.LPStr)> pszRoot As System.Text.StringBuilder, ' LPSTR out
iDrive As Integer ' INT
) As IntPtr
End Function' pszRoot : LPSTR out
' iDrive : INT
Declare PtrSafe Function PathBuildRootA Lib "shlwapi" ( _
ByVal pszRoot As String, _
ByVal iDrive As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathBuildRootA = ctypes.windll.shlwapi.PathBuildRootA
PathBuildRootA.restype = wintypes.LPSTR
PathBuildRootA.argtypes = [
wintypes.LPSTR, # pszRoot : LPSTR out
ctypes.c_int, # iDrive : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathBuildRootA = Fiddle::Function.new(
lib['PathBuildRootA'],
[
Fiddle::TYPE_VOIDP, # pszRoot : LPSTR out
Fiddle::TYPE_INT, # iDrive : INT
],
Fiddle::TYPE_VOIDP)#[link(name = "shlwapi")]
extern "system" {
fn PathBuildRootA(
pszRoot: *mut u8, // LPSTR out
iDrive: i32 // INT
) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr PathBuildRootA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszRoot, int iDrive);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathBuildRootA' -Namespace Win32 -PassThru
# $api::PathBuildRootA(pszRoot, iDrive)#uselib "SHLWAPI.dll"
#func global PathBuildRootA "PathBuildRootA" sptr, sptr
; PathBuildRootA varptr(pszRoot), iDrive ; 戻り値は stat
; pszRoot : LPSTR out -> "sptr"
; iDrive : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global PathBuildRootA "PathBuildRootA" var, int ; res = PathBuildRootA(pszRoot, iDrive) ; pszRoot : LPSTR out -> "var" ; iDrive : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global PathBuildRootA "PathBuildRootA" sptr, int ; res = PathBuildRootA(varptr(pszRoot), iDrive) ; pszRoot : LPSTR out -> "sptr" ; iDrive : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPSTR PathBuildRootA(LPSTR pszRoot, INT iDrive) #uselib "SHLWAPI.dll" #cfunc global PathBuildRootA "PathBuildRootA" var, int ; res = PathBuildRootA(pszRoot, iDrive) ; pszRoot : LPSTR out -> "var" ; iDrive : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPSTR PathBuildRootA(LPSTR pszRoot, INT iDrive) #uselib "SHLWAPI.dll" #cfunc global PathBuildRootA "PathBuildRootA" intptr, int ; res = PathBuildRootA(varptr(pszRoot), iDrive) ; pszRoot : LPSTR out -> "intptr" ; iDrive : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathBuildRootA = shlwapi.NewProc("PathBuildRootA")
)
// pszRoot (LPSTR out), iDrive (INT)
r1, _, err := procPathBuildRootA.Call(
uintptr(pszRoot),
uintptr(iDrive),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPSTRfunction PathBuildRootA(
pszRoot: PAnsiChar; // LPSTR out
iDrive: Integer // INT
): PAnsiChar; stdcall;
external 'SHLWAPI.dll' name 'PathBuildRootA';result := DllCall("SHLWAPI\PathBuildRootA"
, "Ptr", pszRoot ; LPSTR out
, "Int", iDrive ; INT
, "Ptr") ; return: LPSTR●PathBuildRootA(pszRoot, iDrive) = DLL("SHLWAPI.dll", "char* PathBuildRootA(char*, int)")
# 呼び出し: PathBuildRootA(pszRoot, iDrive)
# pszRoot : LPSTR out -> "char*"
# iDrive : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn PathBuildRootA(
pszRoot: [*c]u8, // LPSTR out
iDrive: i32 // INT
) callconv(std.os.windows.WINAPI) [*c]const u8;proc PathBuildRootA(
pszRoot: ptr char, # LPSTR out
iDrive: int32 # INT
): cstring {.importc: "PathBuildRootA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
const(char)* PathBuildRootA(
char* pszRoot, // LPSTR out
int iDrive // INT
);ccall((:PathBuildRootA, "SHLWAPI.dll"), stdcall, Cstring,
(Ptr{UInt8}, Int32),
pszRoot, iDrive)
# pszRoot : LPSTR out -> Ptr{UInt8}
# iDrive : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
const char* PathBuildRootA(
char* pszRoot,
int32_t iDrive);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.PathBuildRootA(pszRoot, iDrive)
-- pszRoot : LPSTR out
-- iDrive : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const PathBuildRootA = lib.func('__stdcall', 'PathBuildRootA', 'void *', ['char *', 'int32_t']);
// PathBuildRootA(pszRoot, iDrive)
// pszRoot : LPSTR out -> 'char *'
// iDrive : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
PathBuildRootA: { parameters: ["buffer", "i32"], result: "pointer" },
});
// lib.symbols.PathBuildRootA(pszRoot, iDrive)
// pszRoot : LPSTR out -> "buffer"
// iDrive : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const char* PathBuildRootA(
char* pszRoot,
int32_t iDrive);
C, "SHLWAPI.dll");
// $ffi->PathBuildRootA(pszRoot, iDrive);
// pszRoot : LPSTR out
// iDrive : INT
// 構造体/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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
Pointer PathBuildRootA(
byte[] pszRoot, // LPSTR out
int iDrive // INT
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun PathBuildRootA = PathBuildRootA(
pszRoot : UInt8*, # LPSTR out
iDrive : Int32 # INT
) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathBuildRootANative = Pointer<Utf8> Function(Pointer<Utf8>, Int32);
typedef PathBuildRootADart = Pointer<Utf8> Function(Pointer<Utf8>, int);
final PathBuildRootA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<PathBuildRootANative, PathBuildRootADart>('PathBuildRootA');
// pszRoot : LPSTR out -> Pointer<Utf8>
// iDrive : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PathBuildRootA(
pszRoot: PAnsiChar; // LPSTR out
iDrive: Integer // INT
): PAnsiChar; stdcall;
external 'SHLWAPI.dll' name 'PathBuildRootA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathBuildRootA"
c_PathBuildRootA :: CString -> Int32 -> IO CString
-- pszRoot : LPSTR out -> CString
-- iDrive : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathbuildroota =
foreign "PathBuildRootA"
(string @-> int32_t @-> returning string)
(* pszRoot : LPSTR out -> string *)
(* iDrive : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("PathBuildRootA" path-build-root-a :convention :stdcall) :string
(psz-root :pointer) ; LPSTR out
(i-drive :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathBuildRootA = Win32::API::More->new('SHLWAPI',
'LPSTR PathBuildRootA(LPSTR pszRoot, int iDrive)');
# my $ret = $PathBuildRootA->Call($pszRoot, $iDrive);
# pszRoot : LPSTR out -> LPSTR
# iDrive : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f PathBuildRootW (Unicode版) — ドライブ番号からルートパス文字列を生成する。