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情報を取得する地理的位置を表す 2 文字の ISO 3166-1 コード、または数値の UN M.49 コードです。オペレーティングシステムで利用可能なコードを取得するには、EnumSystemGeoNames を呼び出します。
geoTypeSYSGEOTYPEin

取得する情報の種類です。指定可能な値は SYSGEOTYPE 列挙体で定義されています。SYSGEOTYPE 列挙体の次の値は GetGeoInfoEx では使用しないでください。

  • GEO_ID

    この値は下位互換性のために提供されています。新しいアプリケーションではこの値を使用せず、代わりに GEO_NAME を使用してください。

  • GEO_LCID

    この値は GetGeoInfoEx 関数ではサポートされていません。

  • GEO_NATION

    この値は GetGeoInfoEx 関数ではサポートされていません。

  • GEO_RFC1766

    この値は GetGeoInfoEx 関数ではサポートされていません。

geoDataLPWSTRoutoptionalGetGeoInfoEx が要求された情報を書き込むバッファーへのポインターです。
geoDataCountINTinGeoData パラメーターが指すバッファーのサイズ (文字数単位) です。要求された情報をバッファーに書き込まず、その情報を格納するために必要なバッファーのサイズのみを関数に返させる場合は、このパラメーターに 0 を設定します。

戻り値の型: INT

公式ドキュメント

2文字の国際標準化機構 (ISO) 3166-1 コード、または数値の国際連合 (UN) Series M, Number 49 (M.49) コードで指定した地理的位置に関する情報を取得します。

戻り値

関数が出力バッファーに書き込んだ地理的位置情報のバイト数です。geoDataCount が 0 の場合、関数は情報をバッファーに書き込まずに、その情報を格納するために必要なバッファーのサイズを返します。

0 は関数が成功しなかったことを示します。拡張エラー情報を取得するには GetLastError を呼び出します。次のいずれかのエラーコードが返される可能性があります。

戻り値コード 説明
ERROR_INSUFFICIENT_BUFFER
指定されたバッファーサイズが十分な大きさではなかったか、誤って NULL に設定されていました。
ERROR_INVALID_PARAMETER
パラメーター値が無効でした。
ERROR_INVALID_FLAGS
フラグに指定された値が無効でした。

解説(Remarks)

2 文字の ISO 3166-1 コードについては、Country Codes - ISO 3166 を参照してください。数値の UN M.49 コードについては、Standard country or area codes for statistical use (M49) を参照してください。

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

各言語での呼び出し定義

// 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)。
const std = @import("std");

extern "kernel32" fn GetGeoInfoEx(
    location: [*c]const u16, // LPWSTR
    geoType: i32, // SYSGEOTYPE
    geoData: [*c]u16, // LPWSTR optional, out
    geoDataCount: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
proc GetGeoInfoEx(
    location: WideCString,  # LPWSTR
    geoType: int32,  # SYSGEOTYPE
    geoData: ptr uint16,  # LPWSTR optional, out
    geoDataCount: int32  # INT
): int32 {.importc: "GetGeoInfoEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int GetGeoInfoEx(
    const(wchar)* location,   // LPWSTR
    int geoType,   // SYSGEOTYPE
    wchar* geoData,   // LPWSTR optional, out
    int geoDataCount   // INT
);
ccall((:GetGeoInfoEx, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, Int32, Ptr{UInt16}, Int32),
      location, geoType, geoData, geoDataCount)
# location : LPWSTR -> Cwstring
# geoType : SYSGEOTYPE -> Int32
# geoData : LPWSTR optional, out -> Ptr{UInt16}
# geoDataCount : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetGeoInfoEx(
    const uint16_t* location,
    int32_t geoType,
    uint16_t* geoData,
    int32_t geoDataCount);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetGeoInfoEx(location, geoType, geoData, geoDataCount)
-- location : LPWSTR
-- geoType : SYSGEOTYPE
-- geoData : LPWSTR optional, out
-- geoDataCount : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetGeoInfoEx = lib.func('__stdcall', 'GetGeoInfoEx', 'int32_t', ['str16', 'int32_t', 'uint16_t *', 'int32_t']);
// GetGeoInfoEx(location, geoType, geoData, geoDataCount)
// location : LPWSTR -> 'str16'
// geoType : SYSGEOTYPE -> 'int32_t'
// geoData : LPWSTR optional, out -> 'uint16_t *'
// geoDataCount : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetGeoInfoEx: { parameters: ["buffer", "i32", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetGeoInfoEx(location, geoType, geoData, geoDataCount)
// location : LPWSTR -> "buffer"
// geoType : SYSGEOTYPE -> "i32"
// geoData : LPWSTR optional, out -> "buffer"
// geoDataCount : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetGeoInfoEx(
    const uint16_t* location,
    int32_t geoType,
    uint16_t* geoData,
    int32_t geoDataCount);
C, "KERNEL32.dll");
// $ffi->GetGeoInfoEx(location, geoType, geoData, geoDataCount);
// location : LPWSTR
// geoType : SYSGEOTYPE
// geoData : LPWSTR optional, out
// geoDataCount : INT
// 構造体/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);
    int GetGeoInfoEx(
        WString location,   // LPWSTR
        int geoType,   // SYSGEOTYPE
        char[] geoData,   // LPWSTR optional, out
        int geoDataCount   // INT
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun GetGeoInfoEx = GetGeoInfoEx(
    location : UInt16*,   # LPWSTR
    geoType : Int32,   # SYSGEOTYPE
    geoData : UInt16*,   # LPWSTR optional, out
    geoDataCount : Int32   # INT
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetGeoInfoExNative = Int32 Function(Pointer<Utf16>, Int32, Pointer<Utf16>, Int32);
typedef GetGeoInfoExDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, int);
final GetGeoInfoEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetGeoInfoExNative, GetGeoInfoExDart>('GetGeoInfoEx');
// location : LPWSTR -> Pointer<Utf16>
// geoType : SYSGEOTYPE -> Int32
// geoData : LPWSTR optional, out -> Pointer<Utf16>
// geoDataCount : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetGeoInfoEx(
  location: PWideChar;   // LPWSTR
  geoType: Integer;   // SYSGEOTYPE
  geoData: PWideChar;   // LPWSTR optional, out
  geoDataCount: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetGeoInfoEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetGeoInfoEx"
  c_GetGeoInfoEx :: CWString -> Int32 -> CWString -> Int32 -> IO Int32
-- location : LPWSTR -> CWString
-- geoType : SYSGEOTYPE -> Int32
-- geoData : LPWSTR optional, out -> CWString
-- geoDataCount : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getgeoinfoex =
  foreign "GetGeoInfoEx"
    ((ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* location : LPWSTR -> (ptr uint16_t) *)
(* geoType : SYSGEOTYPE -> int32_t *)
(* geoData : LPWSTR optional, out -> (ptr uint16_t) *)
(* geoDataCount : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetGeoInfoEx" get-geo-info-ex :convention :stdcall) :int32
  (location (:string :encoding :utf-16le))   ; LPWSTR
  (geo-type :int32)   ; SYSGEOTYPE
  (geo-data :pointer)   ; LPWSTR optional, out
  (geo-data-count :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetGeoInfoEx = Win32::API::More->new('KERNEL32',
    'int GetGeoInfoEx(LPCWSTR location, int geoType, LPWSTR geoData, int geoDataCount)');
# my $ret = $GetGeoInfoEx->Call($location, $geoType, $geoData, $geoDataCount);
# location : LPWSTR -> LPCWSTR
# geoType : SYSGEOTYPE -> int
# geoData : LPWSTR optional, out -> LPWSTR
# geoDataCount : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
公式の関連項目
使用する型