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

GetGeoInfoEx

関数
地域名を指定して地理情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

INT GetGeoInfoEx(
    LPWSTR location,
    SYSGEOTYPE geoType,
    LPWSTR geoData,   // optional
    INT geoDataCount
);

パラメーター

名前方向
locationLPWSTRin
geoTypeSYSGEOTYPEin
geoDataLPWSTRoutoptional
geoDataCountINTin

戻り値の型: INT

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

INT GetGeoInfoEx(
    LPWSTR location,
    SYSGEOTYPE geoType,
    LPWSTR geoData,   // optional
    INT geoDataCount
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int GetGeoInfoEx(
    [MarshalAs(UnmanagedType.LPWStr)] string location,   // LPWSTR
    int geoType,   // SYSGEOTYPE
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder geoData,   // LPWSTR optional, out
    int geoDataCount   // INT
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetGeoInfoEx(
    <MarshalAs(UnmanagedType.LPWStr)> location As String,   ' LPWSTR
    geoType As Integer,   ' SYSGEOTYPE
    <MarshalAs(UnmanagedType.LPWStr)> geoData As System.Text.StringBuilder,   ' LPWSTR optional, out
    geoDataCount As Integer   ' INT
) As Integer
End Function
' location : LPWSTR
' geoType : SYSGEOTYPE
' geoData : LPWSTR optional, out
' geoDataCount : INT
Declare PtrSafe Function GetGeoInfoEx Lib "kernel32" ( _
    ByVal location As LongPtr, _
    ByVal geoType As Long, _
    ByVal geoData As LongPtr, _
    ByVal geoDataCount As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetGeoInfoEx = ctypes.windll.kernel32.GetGeoInfoEx
GetGeoInfoEx.restype = ctypes.c_int
GetGeoInfoEx.argtypes = [
    wintypes.LPCWSTR,  # location : LPWSTR
    ctypes.c_int,  # geoType : SYSGEOTYPE
    wintypes.LPWSTR,  # geoData : LPWSTR optional, out
    ctypes.c_int,  # geoDataCount : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetGeoInfoEx = Fiddle::Function.new(
  lib['GetGeoInfoEx'],
  [
    Fiddle::TYPE_VOIDP,  # location : LPWSTR
    Fiddle::TYPE_INT,  # geoType : SYSGEOTYPE
    Fiddle::TYPE_VOIDP,  # geoData : LPWSTR optional, out
    Fiddle::TYPE_INT,  # geoDataCount : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetGeoInfoEx(
        location: *mut u16,  // LPWSTR
        geoType: i32,  // SYSGEOTYPE
        geoData: *mut u16,  // LPWSTR optional, out
        geoDataCount: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int GetGeoInfoEx([MarshalAs(UnmanagedType.LPWStr)] string location, int geoType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder geoData, int geoDataCount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetGeoInfoEx' -Namespace Win32 -PassThru
# $api::GetGeoInfoEx(location, geoType, geoData, geoDataCount)
#uselib "KERNEL32.dll"
#func global GetGeoInfoEx "GetGeoInfoEx" sptr, sptr, sptr, sptr
; GetGeoInfoEx location, geoType, varptr(geoData), geoDataCount   ; 戻り値は stat
; location : LPWSTR -> "sptr"
; geoType : SYSGEOTYPE -> "sptr"
; geoData : LPWSTR optional, out -> "sptr"
; geoDataCount : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetGeoInfoEx "GetGeoInfoEx" wstr, int, var, int
; res = GetGeoInfoEx(location, geoType, geoData, geoDataCount)
; location : LPWSTR -> "wstr"
; geoType : SYSGEOTYPE -> "int"
; geoData : LPWSTR optional, out -> "var"
; geoDataCount : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetGeoInfoEx(LPWSTR location, SYSGEOTYPE geoType, LPWSTR geoData, INT geoDataCount)
#uselib "KERNEL32.dll"
#cfunc global GetGeoInfoEx "GetGeoInfoEx" wstr, int, var, int
; res = GetGeoInfoEx(location, geoType, geoData, geoDataCount)
; location : LPWSTR -> "wstr"
; geoType : SYSGEOTYPE -> "int"
; geoData : LPWSTR optional, out -> "var"
; geoDataCount : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetGeoInfoEx = kernel32.NewProc("GetGeoInfoEx")
)

// location (LPWSTR), geoType (SYSGEOTYPE), geoData (LPWSTR optional, out), geoDataCount (INT)
r1, _, err := procGetGeoInfoEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(location))),
	uintptr(geoType),
	uintptr(geoData),
	uintptr(geoDataCount),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetGeoInfoEx(
  location: PWideChar;   // LPWSTR
  geoType: Integer;   // SYSGEOTYPE
  geoData: PWideChar;   // LPWSTR optional, out
  geoDataCount: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetGeoInfoEx';
result := DllCall("KERNEL32\GetGeoInfoEx"
    , "WStr", location   ; LPWSTR
    , "Int", geoType   ; SYSGEOTYPE
    , "Ptr", geoData   ; LPWSTR optional, out
    , "Int", geoDataCount   ; INT
    , "Int")   ; return: INT
●GetGeoInfoEx(location, geoType, geoData, geoDataCount) = DLL("KERNEL32.dll", "int GetGeoInfoEx(char*, int, char*, int)")
# 呼び出し: GetGeoInfoEx(location, geoType, geoData, geoDataCount)
# location : LPWSTR -> "char*"
# geoType : SYSGEOTYPE -> "int"
# geoData : LPWSTR optional, out -> "char*"
# geoDataCount : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。