ホーム › System.Ole › VarBstrCmp
VarBstrCmp
関数2つのBSTR文字列をロケール指定で比較する。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT VarBstrCmp(
LPWSTR bstrLeft,
LPWSTR bstrRight,
DWORD lcid,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| bstrLeft | LPWSTR | in | 1 つ目のバリアント。 | ||||||||||||||
| bstrRight | LPWSTR | in | 2 つ目のバリアント。 | ||||||||||||||
| lcid | DWORD | in | UNICODE 文字列と ANSI 文字列のどちらが使用されているかを判定するための、プログラムのロケール識別子。 | ||||||||||||||
| dwFlags | DWORD | in | 以下は比較結果フラグです。
|
戻り値の型: HRESULT
公式ドキュメント
BSTR 型の 2 つのバリアントを比較します。
戻り値
この関数は次のいずれかの値を返すことがあります。
| リターン コード/値 | 説明 |
|---|---|
| bstrLeft は bstrRight より小さい値です。 | |
| パラメーターは等しい値です。 | |
| bstrLeft は bstrRight より大きい値です。 |
解説(Remarks)
この関数は配列やレコードの比較は行いません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT VarBstrCmp(
LPWSTR bstrLeft,
LPWSTR bstrRight,
DWORD lcid,
DWORD dwFlags
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int VarBstrCmp(
[MarshalAs(UnmanagedType.LPWStr)] string bstrLeft, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string bstrRight, // LPWSTR
uint lcid, // DWORD
uint dwFlags // DWORD
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function VarBstrCmp(
<MarshalAs(UnmanagedType.LPWStr)> bstrLeft As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> bstrRight As String, ' LPWSTR
lcid As UInteger, ' DWORD
dwFlags As UInteger ' DWORD
) As Integer
End Function' bstrLeft : LPWSTR
' bstrRight : LPWSTR
' lcid : DWORD
' dwFlags : DWORD
Declare PtrSafe Function VarBstrCmp Lib "oleaut32" ( _
ByVal bstrLeft As LongPtr, _
ByVal bstrRight As LongPtr, _
ByVal lcid As Long, _
ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VarBstrCmp = ctypes.windll.oleaut32.VarBstrCmp
VarBstrCmp.restype = ctypes.c_int
VarBstrCmp.argtypes = [
wintypes.LPCWSTR, # bstrLeft : LPWSTR
wintypes.LPCWSTR, # bstrRight : LPWSTR
wintypes.DWORD, # lcid : DWORD
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
VarBstrCmp = Fiddle::Function.new(
lib['VarBstrCmp'],
[
Fiddle::TYPE_VOIDP, # bstrLeft : LPWSTR
Fiddle::TYPE_VOIDP, # bstrRight : LPWSTR
-Fiddle::TYPE_INT, # lcid : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn VarBstrCmp(
bstrLeft: *mut u16, // LPWSTR
bstrRight: *mut u16, // LPWSTR
lcid: u32, // DWORD
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int VarBstrCmp([MarshalAs(UnmanagedType.LPWStr)] string bstrLeft, [MarshalAs(UnmanagedType.LPWStr)] string bstrRight, uint lcid, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_VarBstrCmp' -Namespace Win32 -PassThru
# $api::VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)#uselib "OLEAUT32.dll"
#func global VarBstrCmp "VarBstrCmp" sptr, sptr, sptr, sptr
; VarBstrCmp bstrLeft, bstrRight, lcid, dwFlags ; 戻り値は stat
; bstrLeft : LPWSTR -> "sptr"
; bstrRight : LPWSTR -> "sptr"
; lcid : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "OLEAUT32.dll"
#cfunc global VarBstrCmp "VarBstrCmp" wstr, wstr, int, int
; res = VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
; bstrLeft : LPWSTR -> "wstr"
; bstrRight : LPWSTR -> "wstr"
; lcid : DWORD -> "int"
; dwFlags : DWORD -> "int"; HRESULT VarBstrCmp(LPWSTR bstrLeft, LPWSTR bstrRight, DWORD lcid, DWORD dwFlags)
#uselib "OLEAUT32.dll"
#cfunc global VarBstrCmp "VarBstrCmp" wstr, wstr, int, int
; res = VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
; bstrLeft : LPWSTR -> "wstr"
; bstrRight : LPWSTR -> "wstr"
; lcid : DWORD -> "int"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procVarBstrCmp = oleaut32.NewProc("VarBstrCmp")
)
// bstrLeft (LPWSTR), bstrRight (LPWSTR), lcid (DWORD), dwFlags (DWORD)
r1, _, err := procVarBstrCmp.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(bstrLeft))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(bstrRight))),
uintptr(lcid),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction VarBstrCmp(
bstrLeft: PWideChar; // LPWSTR
bstrRight: PWideChar; // LPWSTR
lcid: DWORD; // DWORD
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'OLEAUT32.dll' name 'VarBstrCmp';result := DllCall("OLEAUT32\VarBstrCmp"
, "WStr", bstrLeft ; LPWSTR
, "WStr", bstrRight ; LPWSTR
, "UInt", lcid ; DWORD
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags) = DLL("OLEAUT32.dll", "int VarBstrCmp(char*, char*, dword, dword)")
# 呼び出し: VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
# bstrLeft : LPWSTR -> "char*"
# bstrRight : LPWSTR -> "char*"
# lcid : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "oleaut32" fn VarBstrCmp(
bstrLeft: [*c]const u16, // LPWSTR
bstrRight: [*c]const u16, // LPWSTR
lcid: u32, // DWORD
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc VarBstrCmp(
bstrLeft: WideCString, # LPWSTR
bstrRight: WideCString, # LPWSTR
lcid: uint32, # DWORD
dwFlags: uint32 # DWORD
): int32 {.importc: "VarBstrCmp", stdcall, dynlib: "OLEAUT32.dll".}pragma(lib, "oleaut32");
extern(Windows)
int VarBstrCmp(
const(wchar)* bstrLeft, // LPWSTR
const(wchar)* bstrRight, // LPWSTR
uint lcid, // DWORD
uint dwFlags // DWORD
);ccall((:VarBstrCmp, "OLEAUT32.dll"), stdcall, Int32,
(Cwstring, Cwstring, UInt32, UInt32),
bstrLeft, bstrRight, lcid, dwFlags)
# bstrLeft : LPWSTR -> Cwstring
# bstrRight : LPWSTR -> Cwstring
# lcid : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t VarBstrCmp(
const uint16_t* bstrLeft,
const uint16_t* bstrRight,
uint32_t lcid,
uint32_t dwFlags);
]]
local oleaut32 = ffi.load("oleaut32")
-- oleaut32.VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
-- bstrLeft : LPWSTR
-- bstrRight : LPWSTR
-- lcid : DWORD
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLEAUT32.dll');
const VarBstrCmp = lib.func('__stdcall', 'VarBstrCmp', 'int32_t', ['str16', 'str16', 'uint32_t', 'uint32_t']);
// VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
// bstrLeft : LPWSTR -> 'str16'
// bstrRight : LPWSTR -> 'str16'
// lcid : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLEAUT32.dll", {
VarBstrCmp: { parameters: ["buffer", "buffer", "u32", "u32"], result: "i32" },
});
// lib.symbols.VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags)
// bstrLeft : LPWSTR -> "buffer"
// bstrRight : LPWSTR -> "buffer"
// lcid : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t VarBstrCmp(
const uint16_t* bstrLeft,
const uint16_t* bstrRight,
uint32_t lcid,
uint32_t dwFlags);
C, "OLEAUT32.dll");
// $ffi->VarBstrCmp(bstrLeft, bstrRight, lcid, dwFlags);
// bstrLeft : LPWSTR
// bstrRight : LPWSTR
// lcid : DWORD
// dwFlags : DWORD
// 構造体/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 Oleaut32 extends StdCallLibrary {
Oleaut32 INSTANCE = Native.load("oleaut32", Oleaut32.class);
int VarBstrCmp(
WString bstrLeft, // LPWSTR
WString bstrRight, // LPWSTR
int lcid, // DWORD
int dwFlags // DWORD
);
}@[Link("oleaut32")]
lib LibOLEAUT32
fun VarBstrCmp = VarBstrCmp(
bstrLeft : UInt16*, # LPWSTR
bstrRight : UInt16*, # LPWSTR
lcid : UInt32, # DWORD
dwFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef VarBstrCmpNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32);
typedef VarBstrCmpDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int);
final VarBstrCmp = DynamicLibrary.open('OLEAUT32.dll')
.lookupFunction<VarBstrCmpNative, VarBstrCmpDart>('VarBstrCmp');
// bstrLeft : LPWSTR -> Pointer<Utf16>
// bstrRight : LPWSTR -> Pointer<Utf16>
// lcid : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function VarBstrCmp(
bstrLeft: PWideChar; // LPWSTR
bstrRight: PWideChar; // LPWSTR
lcid: DWORD; // DWORD
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'OLEAUT32.dll' name 'VarBstrCmp';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "VarBstrCmp"
c_VarBstrCmp :: CWString -> CWString -> Word32 -> Word32 -> IO Int32
-- bstrLeft : LPWSTR -> CWString
-- bstrRight : LPWSTR -> CWString
-- lcid : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let varbstrcmp =
foreign "VarBstrCmp"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* bstrLeft : LPWSTR -> (ptr uint16_t) *)
(* bstrRight : LPWSTR -> (ptr uint16_t) *)
(* lcid : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)
(cffi:defcfun ("VarBstrCmp" var-bstr-cmp :convention :stdcall) :int32
(bstr-left (:string :encoding :utf-16le)) ; LPWSTR
(bstr-right (:string :encoding :utf-16le)) ; LPWSTR
(lcid :uint32) ; DWORD
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $VarBstrCmp = Win32::API::More->new('OLEAUT32',
'int VarBstrCmp(LPCWSTR bstrLeft, LPCWSTR bstrRight, DWORD lcid, DWORD dwFlags)');
# my $ret = $VarBstrCmp->Call($bstrLeft, $bstrRight, $lcid, $dwFlags);
# bstrLeft : LPWSTR -> LPCWSTR
# bstrRight : LPWSTR -> LPCWSTR
# lcid : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。