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

SetCurrentDirectoryA

関数
現在のプロセスのカレントディレクトリを設定する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

BOOL SetCurrentDirectoryA(
    LPCSTR lpPathName
);

パラメーター

名前方向
lpPathNameLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

BOOL SetCurrentDirectoryA(
    LPCSTR lpPathName
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool SetCurrentDirectoryA(
    [MarshalAs(UnmanagedType.LPStr)] string lpPathName   // LPCSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SetCurrentDirectoryA(
    <MarshalAs(UnmanagedType.LPStr)> lpPathName As String   ' LPCSTR
) As Boolean
End Function
' lpPathName : LPCSTR
Declare PtrSafe Function SetCurrentDirectoryA Lib "kernel32" ( _
    ByVal lpPathName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetCurrentDirectoryA = ctypes.windll.kernel32.SetCurrentDirectoryA
SetCurrentDirectoryA.restype = wintypes.BOOL
SetCurrentDirectoryA.argtypes = [
    wintypes.LPCSTR,  # lpPathName : LPCSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetCurrentDirectoryA = Fiddle::Function.new(
  lib['SetCurrentDirectoryA'],
  [
    Fiddle::TYPE_VOIDP,  # lpPathName : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetCurrentDirectoryA(
        lpPathName: *const u8  // LPCSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern bool SetCurrentDirectoryA([MarshalAs(UnmanagedType.LPStr)] string lpPathName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCurrentDirectoryA' -Namespace Win32 -PassThru
# $api::SetCurrentDirectoryA(lpPathName)
#uselib "KERNEL32.dll"
#func global SetCurrentDirectoryA "SetCurrentDirectoryA" sptr
; SetCurrentDirectoryA lpPathName   ; 戻り値は stat
; lpPathName : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetCurrentDirectoryA "SetCurrentDirectoryA" str
; res = SetCurrentDirectoryA(lpPathName)
; lpPathName : LPCSTR -> "str"
; BOOL SetCurrentDirectoryA(LPCSTR lpPathName)
#uselib "KERNEL32.dll"
#cfunc global SetCurrentDirectoryA "SetCurrentDirectoryA" str
; res = SetCurrentDirectoryA(lpPathName)
; lpPathName : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetCurrentDirectoryA = kernel32.NewProc("SetCurrentDirectoryA")
)

// lpPathName (LPCSTR)
r1, _, err := procSetCurrentDirectoryA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpPathName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetCurrentDirectoryA(
  lpPathName: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetCurrentDirectoryA';
result := DllCall("KERNEL32\SetCurrentDirectoryA"
    , "AStr", lpPathName   ; LPCSTR
    , "Int")   ; return: BOOL
●SetCurrentDirectoryA(lpPathName) = DLL("KERNEL32.dll", "bool SetCurrentDirectoryA(char*)")
# 呼び出し: SetCurrentDirectoryA(lpPathName)
# lpPathName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。