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情報を取得する対象の地理的位置の識別子。詳細については、地理的位置の一覧を参照してください。利用可能な値は、EnumSystemGeoID を呼び出すことで取得できます。
GeoTypeSYSGEOTYPEin

取得する情報の種類。指定可能な値は SYSGEOTYPE 列挙体で定義されています。GeoType の値が GEO_LCID の場合、この関数はロケール識別子を取得します。GeoType の値が GEO_RFC1766 の場合、この関数は RFC 4646 (Windows Vista) に準拠した文字列名を取得します。詳細については、「解説」セクションを参照してください。

Windows XP: GeoTypeGEO_LCID を指定した場合、取得される文字列は 8 桁の 16 進数値になります。

Windows Me: GeoTypeGEO_LCID を指定した場合、取得される文字列は 10 進数値になります。

lpGeoDataLPWSTRoutoptionalこの関数が情報を取得するバッファーへのポインター。
cchDataINTinlpGeoData が指すバッファーのサイズ。サイズは、ANSI 版の関数ではバイト数、Unicode 版の関数ではワード数で指定します。バッファーに必要なサイズを関数に返させたい場合、アプリケーションはこのパラメーターに 0 を設定できます。
LangIdWORDin

Location の値とともに使用する言語の識別子。GeoTypeGEO_RFC1766 または GEO_LCID を指定する場合、アプリケーションはこのパラメーターに 0 を設定できます。この設定により、関数は GetUserDefaultLangID を呼び出して言語識別子を取得します。

GeoTypeGEO_RFC1766 または GEO_LCID 以外の値を指定する場合、アプリケーションはこのパラメーターに 0 を設定する必要があります。

戻り値の型: INT

公式ドキュメント

指定した地理的位置に関する情報を取得します。(Unicode)

戻り値

出力バッファーに取得された地理的位置情報のバイト数 (ANSI) またはワード数 (Unicode) を返します。cchData に 0 を設定した場合、関数はバッファーに必要なサイズを返します。

関数が成功しなかった場合は 0 を返します。拡張エラー情報を取得するには、アプリケーションは GetLastError を呼び出すことができます。この関数は次のいずれかのエラーコードを返すことがあります。

解説(Remarks)

アプリケーションが GeoTypeGEO_RFC1766 を指定する場合、LangId には指定した地理的位置識別子に適した言語識別子を指定する必要があります。適切な言語とは、ロケールに依存しない言語、または指定した識別子に対応するロケールを持つ言語のいずれかです。結果として得られる、RFC 4646 (Windows Vista) に準拠した文字列は、ロケール名を構成します。

たとえば、Location にアメリカ合衆国を表す 0xF4、GeoTypeGEO_RFC1766LangId にロケール非依存の英語を表す 0x09 または英語 (アメリカ合衆国) を表す 0x409 を指定した場合、関数は正常終了時に "en-US" を取得します。実際には、関数は言語のうちロケール固有の部分を無視します。したがって、アプリケーションが LangId に英語 (イギリス) を表す 0x809 を指定した場合も、関数は "en-US" を lpGeoData に書き込みます。

別の例を考えます。Location にアメリカ合衆国を表す 0xF4、GeoTypeGEO_RFC1766LangId に中国語を表す 0x04 を指定した場合、関数は正常終了時に "zh-US" を取得します。これはサポートされているロケールの名前ではありません。

アプリケーションが GeoTypeGEO_LCID を指定した場合、関数は言語識別子をロケール識別子 (LCID) として扱います。提供された地理的識別子と何らかの形で関連付けられている場合、関数はそのロケール識別子を返そうとします。

メモ

winnls.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GetGeoInfo を定義しています。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、「関数プロトタイプの規約」を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn GetGeoInfoW(
    Location: i32, // INT
    GeoType: i32, // SYSGEOTYPE
    lpGeoData: [*c]u16, // LPWSTR optional, out
    cchData: i32, // INT
    LangId: u16 // WORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GetGeoInfoW(
    Location: int32,  # INT
    GeoType: int32,  # SYSGEOTYPE
    lpGeoData: ptr uint16,  # LPWSTR optional, out
    cchData: int32,  # INT
    LangId: uint16  # WORD
): int32 {.importc: "GetGeoInfoW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
int GetGeoInfoW(
    int Location,   // INT
    int GeoType,   // SYSGEOTYPE
    wchar* lpGeoData,   // LPWSTR optional, out
    int cchData,   // INT
    ushort LangId   // WORD
);
ccall((:GetGeoInfoW, "KERNEL32.dll"), stdcall, Int32,
      (Int32, Int32, Ptr{UInt16}, Int32, UInt16),
      Location, GeoType, lpGeoData, cchData, LangId)
# Location : INT -> Int32
# GeoType : SYSGEOTYPE -> Int32
# lpGeoData : LPWSTR optional, out -> Ptr{UInt16}
# cchData : INT -> Int32
# LangId : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetGeoInfoW(
    int32_t Location,
    int32_t GeoType,
    uint16_t* lpGeoData,
    int32_t cchData,
    uint16_t LangId);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
-- Location : INT
-- GeoType : SYSGEOTYPE
-- lpGeoData : LPWSTR optional, out
-- cchData : INT
-- LangId : WORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetGeoInfoW = lib.func('__stdcall', 'GetGeoInfoW', 'int32_t', ['int32_t', 'int32_t', 'uint16_t *', 'int32_t', 'uint16_t']);
// GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
// Location : INT -> 'int32_t'
// GeoType : SYSGEOTYPE -> 'int32_t'
// lpGeoData : LPWSTR optional, out -> 'uint16_t *'
// cchData : INT -> 'int32_t'
// LangId : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetGeoInfoW: { parameters: ["i32", "i32", "buffer", "i32", "u16"], result: "i32" },
});
// lib.symbols.GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId)
// Location : INT -> "i32"
// GeoType : SYSGEOTYPE -> "i32"
// lpGeoData : LPWSTR optional, out -> "buffer"
// cchData : INT -> "i32"
// LangId : WORD -> "u16"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetGeoInfoW(
    int32_t Location,
    int32_t GeoType,
    uint16_t* lpGeoData,
    int32_t cchData,
    uint16_t LangId);
C, "KERNEL32.dll");
// $ffi->GetGeoInfoW(Location, GeoType, lpGeoData, cchData, LangId);
// Location : INT
// GeoType : SYSGEOTYPE
// lpGeoData : LPWSTR optional, out
// cchData : INT
// LangId : WORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    int GetGeoInfoW(
        int Location,   // INT
        int GeoType,   // SYSGEOTYPE
        char[] lpGeoData,   // LPWSTR optional, out
        int cchData,   // INT
        short LangId   // WORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun GetGeoInfoW = GetGeoInfoW(
    Location : Int32,   # INT
    GeoType : Int32,   # SYSGEOTYPE
    lpGeoData : UInt16*,   # LPWSTR optional, out
    cchData : Int32,   # INT
    LangId : UInt16   # WORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetGeoInfoWNative = Int32 Function(Int32, Int32, Pointer<Utf16>, Int32, Uint16);
typedef GetGeoInfoWDart = int Function(int, int, Pointer<Utf16>, int, int);
final GetGeoInfoW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetGeoInfoWNative, GetGeoInfoWDart>('GetGeoInfoW');
// Location : INT -> Int32
// GeoType : SYSGEOTYPE -> Int32
// lpGeoData : LPWSTR optional, out -> Pointer<Utf16>
// cchData : INT -> Int32
// LangId : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetGeoInfoW"
  c_GetGeoInfoW :: Int32 -> Int32 -> CWString -> Int32 -> Word16 -> IO Int32
-- Location : INT -> Int32
-- GeoType : SYSGEOTYPE -> Int32
-- lpGeoData : LPWSTR optional, out -> CWString
-- cchData : INT -> Int32
-- LangId : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getgeoinfow =
  foreign "GetGeoInfoW"
    (int32_t @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> uint16_t @-> returning int32_t)
(* Location : INT -> int32_t *)
(* GeoType : SYSGEOTYPE -> int32_t *)
(* lpGeoData : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchData : INT -> int32_t *)
(* LangId : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetGeoInfoW" get-geo-info-w :convention :stdcall) :int32
  (location :int32)   ; INT
  (geo-type :int32)   ; SYSGEOTYPE
  (lp-geo-data :pointer)   ; LPWSTR optional, out
  (cch-data :int32)   ; INT
  (lang-id :uint16))   ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetGeoInfoW = Win32::API::More->new('KERNEL32',
    'int GetGeoInfoW(int Location, int GeoType, LPWSTR lpGeoData, int cchData, WORD LangId)');
# my $ret = $GetGeoInfoW->Call($Location, $GeoType, $lpGeoData, $cchData, $LangId);
# Location : INT -> int
# GeoType : SYSGEOTYPE -> int
# lpGeoData : LPWSTR optional, out -> LPWSTR
# cchData : INT -> int
# LangId : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
類似 API
公式の関連項目
使用する型