ホーム › System.WindowsProgramming › GetPrivateProfileStructW
GetPrivateProfileStructW
関数iniファイルからチェックサム付き構造体データをUnicodeで取得する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetPrivateProfileStructW(
LPCWSTR lpszSection,
LPCWSTR lpszKey,
void* lpStruct, // optional
DWORD uSizeStruct,
LPCWSTR szFile // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpszSection | LPCWSTR | in |
| lpszKey | LPCWSTR | in |
| lpStruct | void* | outoptional |
| uSizeStruct | DWORD | in |
| szFile | LPCWSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetPrivateProfileStructW(
LPCWSTR lpszSection,
LPCWSTR lpszKey,
void* lpStruct, // optional
DWORD uSizeStruct,
LPCWSTR szFile // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetPrivateProfileStructW(
[MarshalAs(UnmanagedType.LPWStr)] string lpszSection, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpszKey, // LPCWSTR
IntPtr lpStruct, // void* optional, out
uint uSizeStruct, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string szFile // LPCWSTR optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetPrivateProfileStructW(
<MarshalAs(UnmanagedType.LPWStr)> lpszSection As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpszKey As String, ' LPCWSTR
lpStruct As IntPtr, ' void* optional, out
uSizeStruct As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szFile As String ' LPCWSTR optional
) As Boolean
End Function' lpszSection : LPCWSTR
' lpszKey : LPCWSTR
' lpStruct : void* optional, out
' uSizeStruct : DWORD
' szFile : LPCWSTR optional
Declare PtrSafe Function GetPrivateProfileStructW Lib "kernel32" ( _
ByVal lpszSection As LongPtr, _
ByVal lpszKey As LongPtr, _
ByVal lpStruct As LongPtr, _
ByVal uSizeStruct As Long, _
ByVal szFile 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
GetPrivateProfileStructW = ctypes.windll.kernel32.GetPrivateProfileStructW
GetPrivateProfileStructW.restype = wintypes.BOOL
GetPrivateProfileStructW.argtypes = [
wintypes.LPCWSTR, # lpszSection : LPCWSTR
wintypes.LPCWSTR, # lpszKey : LPCWSTR
ctypes.POINTER(None), # lpStruct : void* optional, out
wintypes.DWORD, # uSizeStruct : DWORD
wintypes.LPCWSTR, # szFile : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetPrivateProfileStructW = Fiddle::Function.new(
lib['GetPrivateProfileStructW'],
[
Fiddle::TYPE_VOIDP, # lpszSection : LPCWSTR
Fiddle::TYPE_VOIDP, # lpszKey : LPCWSTR
Fiddle::TYPE_VOIDP, # lpStruct : void* optional, out
-Fiddle::TYPE_INT, # uSizeStruct : DWORD
Fiddle::TYPE_VOIDP, # szFile : LPCWSTR optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GetPrivateProfileStructW(
lpszSection: *const u16, // LPCWSTR
lpszKey: *const u16, // LPCWSTR
lpStruct: *mut (), // void* optional, out
uSizeStruct: u32, // DWORD
szFile: *const u16 // LPCWSTR optional
) -> 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 GetPrivateProfileStructW([MarshalAs(UnmanagedType.LPWStr)] string lpszSection, [MarshalAs(UnmanagedType.LPWStr)] string lpszKey, IntPtr lpStruct, uint uSizeStruct, [MarshalAs(UnmanagedType.LPWStr)] string szFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetPrivateProfileStructW' -Namespace Win32 -PassThru
# $api::GetPrivateProfileStructW(lpszSection, lpszKey, lpStruct, uSizeStruct, szFile)#uselib "KERNEL32.dll"
#func global GetPrivateProfileStructW "GetPrivateProfileStructW" wptr, wptr, wptr, wptr, wptr
; GetPrivateProfileStructW lpszSection, lpszKey, lpStruct, uSizeStruct, szFile ; 戻り値は stat
; lpszSection : LPCWSTR -> "wptr"
; lpszKey : LPCWSTR -> "wptr"
; lpStruct : void* optional, out -> "wptr"
; uSizeStruct : DWORD -> "wptr"
; szFile : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetPrivateProfileStructW "GetPrivateProfileStructW" wstr, wstr, sptr, int, wstr
; res = GetPrivateProfileStructW(lpszSection, lpszKey, lpStruct, uSizeStruct, szFile)
; lpszSection : LPCWSTR -> "wstr"
; lpszKey : LPCWSTR -> "wstr"
; lpStruct : void* optional, out -> "sptr"
; uSizeStruct : DWORD -> "int"
; szFile : LPCWSTR optional -> "wstr"; BOOL GetPrivateProfileStructW(LPCWSTR lpszSection, LPCWSTR lpszKey, void* lpStruct, DWORD uSizeStruct, LPCWSTR szFile)
#uselib "KERNEL32.dll"
#cfunc global GetPrivateProfileStructW "GetPrivateProfileStructW" wstr, wstr, intptr, int, wstr
; res = GetPrivateProfileStructW(lpszSection, lpszKey, lpStruct, uSizeStruct, szFile)
; lpszSection : LPCWSTR -> "wstr"
; lpszKey : LPCWSTR -> "wstr"
; lpStruct : void* optional, out -> "intptr"
; uSizeStruct : DWORD -> "int"
; szFile : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetPrivateProfileStructW = kernel32.NewProc("GetPrivateProfileStructW")
)
// lpszSection (LPCWSTR), lpszKey (LPCWSTR), lpStruct (void* optional, out), uSizeStruct (DWORD), szFile (LPCWSTR optional)
r1, _, err := procGetPrivateProfileStructW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszSection))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszKey))),
uintptr(lpStruct),
uintptr(uSizeStruct),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFile))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetPrivateProfileStructW(
lpszSection: PWideChar; // LPCWSTR
lpszKey: PWideChar; // LPCWSTR
lpStruct: Pointer; // void* optional, out
uSizeStruct: DWORD; // DWORD
szFile: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetPrivateProfileStructW';result := DllCall("KERNEL32\GetPrivateProfileStructW"
, "WStr", lpszSection ; LPCWSTR
, "WStr", lpszKey ; LPCWSTR
, "Ptr", lpStruct ; void* optional, out
, "UInt", uSizeStruct ; DWORD
, "WStr", szFile ; LPCWSTR optional
, "Int") ; return: BOOL●GetPrivateProfileStructW(lpszSection, lpszKey, lpStruct, uSizeStruct, szFile) = DLL("KERNEL32.dll", "bool GetPrivateProfileStructW(char*, char*, void*, dword, char*)")
# 呼び出し: GetPrivateProfileStructW(lpszSection, lpszKey, lpStruct, uSizeStruct, szFile)
# lpszSection : LPCWSTR -> "char*"
# lpszKey : LPCWSTR -> "char*"
# lpStruct : void* optional, out -> "void*"
# uSizeStruct : DWORD -> "dword"
# szFile : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。