ホーム › System.Environment › SetCurrentDirectoryW
SetCurrentDirectoryW
関数現在のプロセスのカレントディレクトリを設定する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetCurrentDirectoryW(
LPCWSTR lpPathName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpPathName | LPCWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetCurrentDirectoryW(
LPCWSTR lpPathName
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool SetCurrentDirectoryW(
[MarshalAs(UnmanagedType.LPWStr)] string lpPathName // LPCWSTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SetCurrentDirectoryW(
<MarshalAs(UnmanagedType.LPWStr)> lpPathName As String ' LPCWSTR
) As Boolean
End Function' lpPathName : LPCWSTR
Declare PtrSafe Function SetCurrentDirectoryW Lib "kernel32" ( _
ByVal lpPathName 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
SetCurrentDirectoryW = ctypes.windll.kernel32.SetCurrentDirectoryW
SetCurrentDirectoryW.restype = wintypes.BOOL
SetCurrentDirectoryW.argtypes = [
wintypes.LPCWSTR, # lpPathName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetCurrentDirectoryW = Fiddle::Function.new(
lib['SetCurrentDirectoryW'],
[
Fiddle::TYPE_VOIDP, # lpPathName : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn SetCurrentDirectoryW(
lpPathName: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern bool SetCurrentDirectoryW([MarshalAs(UnmanagedType.LPWStr)] string lpPathName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCurrentDirectoryW' -Namespace Win32 -PassThru
# $api::SetCurrentDirectoryW(lpPathName)#uselib "KERNEL32.dll"
#func global SetCurrentDirectoryW "SetCurrentDirectoryW" wptr
; SetCurrentDirectoryW lpPathName ; 戻り値は stat
; lpPathName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetCurrentDirectoryW "SetCurrentDirectoryW" wstr
; res = SetCurrentDirectoryW(lpPathName)
; lpPathName : LPCWSTR -> "wstr"; BOOL SetCurrentDirectoryW(LPCWSTR lpPathName)
#uselib "KERNEL32.dll"
#cfunc global SetCurrentDirectoryW "SetCurrentDirectoryW" wstr
; res = SetCurrentDirectoryW(lpPathName)
; lpPathName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetCurrentDirectoryW = kernel32.NewProc("SetCurrentDirectoryW")
)
// lpPathName (LPCWSTR)
r1, _, err := procSetCurrentDirectoryW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpPathName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetCurrentDirectoryW(
lpPathName: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetCurrentDirectoryW';result := DllCall("KERNEL32\SetCurrentDirectoryW"
, "WStr", lpPathName ; LPCWSTR
, "Int") ; return: BOOL●SetCurrentDirectoryW(lpPathName) = DLL("KERNEL32.dll", "bool SetCurrentDirectoryW(char*)")
# 呼び出し: SetCurrentDirectoryW(lpPathName)
# lpPathName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。