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

GetProfileSectionA

関数
win.iniの指定セクション全体をANSIで取得する旧式関数。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetProfileSectionA(
    LPCSTR lpAppName,
    LPSTR lpReturnedString,   // optional
    DWORD nSize
);

パラメーター

名前方向
lpAppNameLPCSTRin
lpReturnedStringLPSTRoutoptional
nSizeDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetProfileSectionA(
    LPCSTR lpAppName,
    LPSTR lpReturnedString,   // optional
    DWORD nSize
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint GetProfileSectionA(
    [MarshalAs(UnmanagedType.LPStr)] string lpAppName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpReturnedString,   // LPSTR optional, out
    uint nSize   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetProfileSectionA(
    <MarshalAs(UnmanagedType.LPStr)> lpAppName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpReturnedString As System.Text.StringBuilder,   ' LPSTR optional, out
    nSize As UInteger   ' DWORD
) As UInteger
End Function
' lpAppName : LPCSTR
' lpReturnedString : LPSTR optional, out
' nSize : DWORD
Declare PtrSafe Function GetProfileSectionA Lib "kernel32" ( _
    ByVal lpAppName As String, _
    ByVal lpReturnedString As String, _
    ByVal nSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetProfileSectionA = ctypes.windll.kernel32.GetProfileSectionA
GetProfileSectionA.restype = wintypes.DWORD
GetProfileSectionA.argtypes = [
    wintypes.LPCSTR,  # lpAppName : LPCSTR
    wintypes.LPSTR,  # lpReturnedString : LPSTR optional, out
    wintypes.DWORD,  # nSize : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetProfileSectionA = Fiddle::Function.new(
  lib['GetProfileSectionA'],
  [
    Fiddle::TYPE_VOIDP,  # lpAppName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpReturnedString : LPSTR optional, out
    -Fiddle::TYPE_INT,  # nSize : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetProfileSectionA(
        lpAppName: *const u8,  // LPCSTR
        lpReturnedString: *mut u8,  // LPSTR optional, out
        nSize: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern uint GetProfileSectionA([MarshalAs(UnmanagedType.LPStr)] string lpAppName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpReturnedString, uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetProfileSectionA' -Namespace Win32 -PassThru
# $api::GetProfileSectionA(lpAppName, lpReturnedString, nSize)
#uselib "KERNEL32.dll"
#func global GetProfileSectionA "GetProfileSectionA" sptr, sptr, sptr
; GetProfileSectionA lpAppName, varptr(lpReturnedString), nSize   ; 戻り値は stat
; lpAppName : LPCSTR -> "sptr"
; lpReturnedString : LPSTR optional, out -> "sptr"
; nSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetProfileSectionA "GetProfileSectionA" str, var, int
; res = GetProfileSectionA(lpAppName, lpReturnedString, nSize)
; lpAppName : LPCSTR -> "str"
; lpReturnedString : LPSTR optional, out -> "var"
; nSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetProfileSectionA(LPCSTR lpAppName, LPSTR lpReturnedString, DWORD nSize)
#uselib "KERNEL32.dll"
#cfunc global GetProfileSectionA "GetProfileSectionA" str, var, int
; res = GetProfileSectionA(lpAppName, lpReturnedString, nSize)
; lpAppName : LPCSTR -> "str"
; lpReturnedString : LPSTR optional, out -> "var"
; nSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetProfileSectionA = kernel32.NewProc("GetProfileSectionA")
)

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