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

WriteProfileSectionA

関数
win.iniの指定セクション全体をANSIで書き込む旧式関数。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL WriteProfileSectionA(
    LPCSTR lpAppName,
    LPCSTR lpString
);

パラメーター

名前方向
lpAppNameLPCSTRin
lpStringLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

WriteProfileSectionA = ctypes.windll.kernel32.WriteProfileSectionA
WriteProfileSectionA.restype = wintypes.BOOL
WriteProfileSectionA.argtypes = [
    wintypes.LPCSTR,  # lpAppName : LPCSTR
    wintypes.LPCSTR,  # lpString : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
WriteProfileSectionA = Fiddle::Function.new(
  lib['WriteProfileSectionA'],
  [
    Fiddle::TYPE_VOIDP,  # lpAppName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpString : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn WriteProfileSectionA(
        lpAppName: *const u8,  // LPCSTR
        lpString: *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, SetLastError = true)]
public static extern bool WriteProfileSectionA([MarshalAs(UnmanagedType.LPStr)] string lpAppName, [MarshalAs(UnmanagedType.LPStr)] string lpString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_WriteProfileSectionA' -Namespace Win32 -PassThru
# $api::WriteProfileSectionA(lpAppName, lpString)
#uselib "KERNEL32.dll"
#func global WriteProfileSectionA "WriteProfileSectionA" sptr, sptr
; WriteProfileSectionA lpAppName, lpString   ; 戻り値は stat
; lpAppName : LPCSTR -> "sptr"
; lpString : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global WriteProfileSectionA "WriteProfileSectionA" str, str
; res = WriteProfileSectionA(lpAppName, lpString)
; lpAppName : LPCSTR -> "str"
; lpString : LPCSTR -> "str"
; BOOL WriteProfileSectionA(LPCSTR lpAppName, LPCSTR lpString)
#uselib "KERNEL32.dll"
#cfunc global WriteProfileSectionA "WriteProfileSectionA" str, str
; res = WriteProfileSectionA(lpAppName, lpString)
; lpAppName : LPCSTR -> "str"
; lpString : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procWriteProfileSectionA = kernel32.NewProc("WriteProfileSectionA")
)

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