ホーム › System.Console › AddConsoleAliasW
AddConsoleAliasW
関数指定した実行ファイル用のコンソールエイリアスを登録する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL AddConsoleAliasW(
LPWSTR Source,
LPWSTR Target,
LPWSTR ExeName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Source | LPWSTR | in |
| Target | LPWSTR | in |
| ExeName | LPWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL AddConsoleAliasW(
LPWSTR Source,
LPWSTR Target,
LPWSTR ExeName
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool AddConsoleAliasW(
[MarshalAs(UnmanagedType.LPWStr)] string Source, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string Target, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string ExeName // LPWSTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AddConsoleAliasW(
<MarshalAs(UnmanagedType.LPWStr)> Source As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> Target As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> ExeName As String ' LPWSTR
) As Boolean
End Function' Source : LPWSTR
' Target : LPWSTR
' ExeName : LPWSTR
Declare PtrSafe Function AddConsoleAliasW Lib "kernel32" ( _
ByVal Source As LongPtr, _
ByVal Target As LongPtr, _
ByVal ExeName As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AddConsoleAliasW = ctypes.windll.kernel32.AddConsoleAliasW
AddConsoleAliasW.restype = wintypes.BOOL
AddConsoleAliasW.argtypes = [
wintypes.LPCWSTR, # Source : LPWSTR
wintypes.LPCWSTR, # Target : LPWSTR
wintypes.LPCWSTR, # ExeName : LPWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
AddConsoleAliasW = Fiddle::Function.new(
lib['AddConsoleAliasW'],
[
Fiddle::TYPE_VOIDP, # Source : LPWSTR
Fiddle::TYPE_VOIDP, # Target : LPWSTR
Fiddle::TYPE_VOIDP, # ExeName : LPWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn AddConsoleAliasW(
Source: *mut u16, // LPWSTR
Target: *mut u16, // LPWSTR
ExeName: *mut u16 // LPWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool AddConsoleAliasW([MarshalAs(UnmanagedType.LPWStr)] string Source, [MarshalAs(UnmanagedType.LPWStr)] string Target, [MarshalAs(UnmanagedType.LPWStr)] string ExeName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_AddConsoleAliasW' -Namespace Win32 -PassThru
# $api::AddConsoleAliasW(Source, Target, ExeName)#uselib "KERNEL32.dll"
#func global AddConsoleAliasW "AddConsoleAliasW" wptr, wptr, wptr
; AddConsoleAliasW Source, Target, ExeName ; 戻り値は stat
; Source : LPWSTR -> "wptr"
; Target : LPWSTR -> "wptr"
; ExeName : LPWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global AddConsoleAliasW "AddConsoleAliasW" wstr, wstr, wstr
; res = AddConsoleAliasW(Source, Target, ExeName)
; Source : LPWSTR -> "wstr"
; Target : LPWSTR -> "wstr"
; ExeName : LPWSTR -> "wstr"; BOOL AddConsoleAliasW(LPWSTR Source, LPWSTR Target, LPWSTR ExeName)
#uselib "KERNEL32.dll"
#cfunc global AddConsoleAliasW "AddConsoleAliasW" wstr, wstr, wstr
; res = AddConsoleAliasW(Source, Target, ExeName)
; Source : LPWSTR -> "wstr"
; Target : LPWSTR -> "wstr"
; ExeName : LPWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procAddConsoleAliasW = kernel32.NewProc("AddConsoleAliasW")
)
// Source (LPWSTR), Target (LPWSTR), ExeName (LPWSTR)
r1, _, err := procAddConsoleAliasW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Source))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Target))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ExeName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction AddConsoleAliasW(
Source: PWideChar; // LPWSTR
Target: PWideChar; // LPWSTR
ExeName: PWideChar // LPWSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'AddConsoleAliasW';result := DllCall("KERNEL32\AddConsoleAliasW"
, "WStr", Source ; LPWSTR
, "WStr", Target ; LPWSTR
, "WStr", ExeName ; LPWSTR
, "Int") ; return: BOOL●AddConsoleAliasW(Source, Target, ExeName) = DLL("KERNEL32.dll", "bool AddConsoleAliasW(char*, char*, char*)")
# 呼び出し: AddConsoleAliasW(Source, Target, ExeName)
# Source : LPWSTR -> "char*"
# Target : LPWSTR -> "char*"
# ExeName : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。