Win32 API 日本語リファレンス
ホームGlobalization › GetGeoInfoW

GetGeoInfoW

関数
指定地域識別子の地理情報を取得する。Unicode版。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

INT GetGeoInfoW(
    INT Location,
    SYSGEOTYPE GeoType,
    LPWSTR lpGeoData,   // optional
    INT cchData,
    WORD LangId
);

パラメーター

名前方向
LocationINTin
GeoTypeSYSGEOTYPEin
lpGeoDataLPWSTRoutoptional
cchDataINTin
LangIdWORDin

戻り値の型: INT

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

INT GetGeoInfoW(
    INT Location,
    SYSGEOTYPE GeoType,
    LPWSTR lpGeoData,   // optional
    INT cchData,
    WORD LangId
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetGeoInfoW(
    int Location,   // INT
    int GeoType,   // SYSGEOTYPE
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpGeoData,   // LPWSTR optional, out
    int cchData,   // INT
    ushort LangId   // WORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetGeoInfoW(
    Location As Integer,   ' INT
    GeoType As Integer,   ' SYSGEOTYPE
    <MarshalAs(UnmanagedType.LPWStr)> lpGeoData As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchData As Integer,   ' INT
    LangId As UShort   ' WORD
) As Integer
End Function
' Location : INT
' GeoType : SYSGEOTYPE
' lpGeoData : LPWSTR optional, out
' cchData : INT
' LangId : WORD
Declare PtrSafe Function GetGeoInfoW Lib "kernel32" ( _
    ByVal Location As Long, _
    ByVal GeoType As Long, _
    ByVal lpGeoData As LongPtr, _
    ByVal cchData As Long, _
    ByVal LangId As Integer) 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

GetGeoInfoW = ctypes.windll.kernel32.GetGeoInfoW
GetGeoInfoW.restype = ctypes.c_int
GetGeoInfoW.argtypes = [
    ctypes.c_int,  # Location : INT
    ctypes.c_int,  # GeoType : SYSGEOTYPE
    wintypes.LPWSTR,  # lpGeoData : LPWSTR optional, out
    ctypes.c_int,  # cchData : INT
    ctypes.c_ushort,  # LangId : WORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetGeoInfoW = Fiddle::Function.new(
  lib['GetGeoInfoW'],
  [
    Fiddle::TYPE_INT,  # Location : INT
    Fiddle::TYPE_INT,  # GeoType : SYSGEOTYPE
    Fiddle::TYPE_VOIDP,  # lpGeoData : LPWSTR optional, out
    Fiddle::TYPE_INT,  # cchData : INT
    -Fiddle::TYPE_SHORT,  # LangId : WORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetGeoInfoW(
        Location: i32,  // INT
        GeoType: i32,  // SYSGEOTYPE
        lpGeoData: *mut u16,  // LPWSTR optional, out
        cchData: i32,  // INT
        LangId: u16  // WORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetGeoInfoW(int Location, int GeoType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpGeoData, int cchData, ushort LangId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetGeoInfoW' -Namespace Win32 -PassThru
# $api::GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
#uselib "KERNEL32.dll"
#func global GetGeoInfoW "GetGeoInfoW" wptr, wptr, wptr, wptr, wptr
; GetGeoInfoW Location, GeoType, varptr(lpGeoData), cchData, LangId   ; 戻り値は stat
; Location : INT -> "wptr"
; GeoType : SYSGEOTYPE -> "wptr"
; lpGeoData : LPWSTR optional, out -> "wptr"
; cchData : INT -> "wptr"
; LangId : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetGeoInfoW "GetGeoInfoW" int, int, var, int, int
; res = GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
; Location : INT -> "int"
; GeoType : SYSGEOTYPE -> "int"
; lpGeoData : LPWSTR optional, out -> "var"
; cchData : INT -> "int"
; LangId : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetGeoInfoW(INT Location, SYSGEOTYPE GeoType, LPWSTR lpGeoData, INT cchData, WORD LangId)
#uselib "KERNEL32.dll"
#cfunc global GetGeoInfoW "GetGeoInfoW" int, int, var, int, int
; res = GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
; Location : INT -> "int"
; GeoType : SYSGEOTYPE -> "int"
; lpGeoData : LPWSTR optional, out -> "var"
; cchData : INT -> "int"
; LangId : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetGeoInfoW = kernel32.NewProc("GetGeoInfoW")
)

// Location (INT), GeoType (SYSGEOTYPE), lpGeoData (LPWSTR optional, out), cchData (INT), LangId (WORD)
r1, _, err := procGetGeoInfoW.Call(
	uintptr(Location),
	uintptr(GeoType),
	uintptr(lpGeoData),
	uintptr(cchData),
	uintptr(LangId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetGeoInfoW(
  Location: Integer;   // INT
  GeoType: Integer;   // SYSGEOTYPE
  lpGeoData: PWideChar;   // LPWSTR optional, out
  cchData: Integer;   // INT
  LangId: Word   // WORD
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetGeoInfoW';
result := DllCall("KERNEL32\GetGeoInfoW"
    , "Int", Location   ; INT
    , "Int", GeoType   ; SYSGEOTYPE
    , "Ptr", lpGeoData   ; LPWSTR optional, out
    , "Int", cchData   ; INT
    , "UShort", LangId   ; WORD
    , "Int")   ; return: INT
●GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId) = DLL("KERNEL32.dll", "int GetGeoInfoW(int, int, char*, int, int)")
# 呼び出し: GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
# Location : INT -> "int"
# GeoType : SYSGEOTYPE -> "int"
# lpGeoData : LPWSTR optional, out -> "char*"
# cchData : INT -> "int"
# LangId : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。