Win32 API 日本語リファレンス
ホームUI.Shell › UrlCompareA

UrlCompareA

関数
2つのURLを比較し大小関係を返す。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT UrlCompareA(
    LPCSTR psz1,
    LPCSTR psz2,
    BOOL fIgnoreSlash
);

パラメーター

名前方向説明
psz1LPCSTRin1 つ目の URL を格納する、最大長 INTERNET_MAX_URL_LENGTH の null 終端文字列です。
psz2LPCSTRin2 つ目の URL を格納する、最大長 INTERNET_MAX_URL_LENGTH の null 終端文字列です。
fIgnoreSlashBOOLinいずれか一方または両方の URL の末尾の '/' 文字を UrlCompare に無視させる場合は TRUE に設定する値です。

戻り値の型: INT

公式ドキュメント

2 つの URL 文字列を大文字と小文字を区別して比較します。(ANSI)

戻り値

型: int

2 つの文字列が等しい場合は 0 を返します。fIgnoreSlashTRUE に設定されており、いずれかの文字列の末尾に '' 文字がある場合も、この関数は 0 を返します。psz1 が指す文字列が psz2 が指す文字列より小さい場合は負の整数を返します。それ以外の場合は正の整数を返します。

解説(Remarks)

最良の結果を得るには、まず UrlCanonicalize で URL を正規化してください。その後、正規化された URL を UrlCompare で比較します。

メモ

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

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

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT UrlCompareA(
    LPCSTR psz1,
    LPCSTR psz2,
    BOOL fIgnoreSlash
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int UrlCompareA(
    [MarshalAs(UnmanagedType.LPStr)] string psz1,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string psz2,   // LPCSTR
    bool fIgnoreSlash   // BOOL
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function UrlCompareA(
    <MarshalAs(UnmanagedType.LPStr)> psz1 As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> psz2 As String,   ' LPCSTR
    fIgnoreSlash As Boolean   ' BOOL
) As Integer
End Function
' psz1 : LPCSTR
' psz2 : LPCSTR
' fIgnoreSlash : BOOL
Declare PtrSafe Function UrlCompareA Lib "shlwapi" ( _
    ByVal psz1 As String, _
    ByVal psz2 As String, _
    ByVal fIgnoreSlash As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UrlCompareA = ctypes.windll.shlwapi.UrlCompareA
UrlCompareA.restype = ctypes.c_int
UrlCompareA.argtypes = [
    wintypes.LPCSTR,  # psz1 : LPCSTR
    wintypes.LPCSTR,  # psz2 : LPCSTR
    wintypes.BOOL,  # fIgnoreSlash : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
UrlCompareA = Fiddle::Function.new(
  lib['UrlCompareA'],
  [
    Fiddle::TYPE_VOIDP,  # psz1 : LPCSTR
    Fiddle::TYPE_VOIDP,  # psz2 : LPCSTR
    Fiddle::TYPE_INT,  # fIgnoreSlash : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn UrlCompareA(
        psz1: *const u8,  // LPCSTR
        psz2: *const u8,  // LPCSTR
        fIgnoreSlash: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern int UrlCompareA([MarshalAs(UnmanagedType.LPStr)] string psz1, [MarshalAs(UnmanagedType.LPStr)] string psz2, bool fIgnoreSlash);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_UrlCompareA' -Namespace Win32 -PassThru
# $api::UrlCompareA(psz1, psz2, fIgnoreSlash)
#uselib "SHLWAPI.dll"
#func global UrlCompareA "UrlCompareA" sptr, sptr, sptr
; UrlCompareA psz1, psz2, fIgnoreSlash   ; 戻り値は stat
; psz1 : LPCSTR -> "sptr"
; psz2 : LPCSTR -> "sptr"
; fIgnoreSlash : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global UrlCompareA "UrlCompareA" str, str, int
; res = UrlCompareA(psz1, psz2, fIgnoreSlash)
; psz1 : LPCSTR -> "str"
; psz2 : LPCSTR -> "str"
; fIgnoreSlash : BOOL -> "int"
; INT UrlCompareA(LPCSTR psz1, LPCSTR psz2, BOOL fIgnoreSlash)
#uselib "SHLWAPI.dll"
#cfunc global UrlCompareA "UrlCompareA" str, str, int
; res = UrlCompareA(psz1, psz2, fIgnoreSlash)
; psz1 : LPCSTR -> "str"
; psz2 : LPCSTR -> "str"
; fIgnoreSlash : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procUrlCompareA = shlwapi.NewProc("UrlCompareA")
)

// psz1 (LPCSTR), psz2 (LPCSTR), fIgnoreSlash (BOOL)
r1, _, err := procUrlCompareA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(psz1))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(psz2))),
	uintptr(fIgnoreSlash),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function UrlCompareA(
  psz1: PAnsiChar;   // LPCSTR
  psz2: PAnsiChar;   // LPCSTR
  fIgnoreSlash: BOOL   // BOOL
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'UrlCompareA';
result := DllCall("SHLWAPI\UrlCompareA"
    , "AStr", psz1   ; LPCSTR
    , "AStr", psz2   ; LPCSTR
    , "Int", fIgnoreSlash   ; BOOL
    , "Int")   ; return: INT
●UrlCompareA(psz1, psz2, fIgnoreSlash) = DLL("SHLWAPI.dll", "int UrlCompareA(char*, char*, bool)")
# 呼び出し: UrlCompareA(psz1, psz2, fIgnoreSlash)
# psz1 : LPCSTR -> "char*"
# psz2 : LPCSTR -> "char*"
# fIgnoreSlash : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shlwapi" fn UrlCompareA(
    psz1: [*c]const u8, // LPCSTR
    psz2: [*c]const u8, // LPCSTR
    fIgnoreSlash: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;
proc UrlCompareA(
    psz1: cstring,  # LPCSTR
    psz2: cstring,  # LPCSTR
    fIgnoreSlash: int32  # BOOL
): int32 {.importc: "UrlCompareA", stdcall, dynlib: "SHLWAPI.dll".}
pragma(lib, "shlwapi");
extern(Windows)
int UrlCompareA(
    const(char)* psz1,   // LPCSTR
    const(char)* psz2,   // LPCSTR
    int fIgnoreSlash   // BOOL
);
ccall((:UrlCompareA, "SHLWAPI.dll"), stdcall, Int32,
      (Cstring, Cstring, Int32),
      psz1, psz2, fIgnoreSlash)
# psz1 : LPCSTR -> Cstring
# psz2 : LPCSTR -> Cstring
# fIgnoreSlash : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t UrlCompareA(
    const char* psz1,
    const char* psz2,
    int32_t fIgnoreSlash);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.UrlCompareA(psz1, psz2, fIgnoreSlash)
-- psz1 : LPCSTR
-- psz2 : LPCSTR
-- fIgnoreSlash : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const UrlCompareA = lib.func('__stdcall', 'UrlCompareA', 'int32_t', ['str', 'str', 'int32_t']);
// UrlCompareA(psz1, psz2, fIgnoreSlash)
// psz1 : LPCSTR -> 'str'
// psz2 : LPCSTR -> 'str'
// fIgnoreSlash : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHLWAPI.dll", {
  UrlCompareA: { parameters: ["buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.UrlCompareA(psz1, psz2, fIgnoreSlash)
// psz1 : LPCSTR -> "buffer"
// psz2 : LPCSTR -> "buffer"
// fIgnoreSlash : BOOL -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t UrlCompareA(
    const char* psz1,
    const char* psz2,
    int32_t fIgnoreSlash);
C, "SHLWAPI.dll");
// $ffi->UrlCompareA(psz1, psz2, fIgnoreSlash);
// psz1 : LPCSTR
// psz2 : LPCSTR
// fIgnoreSlash : BOOL
// 構造体/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 Shlwapi extends StdCallLibrary {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
    int UrlCompareA(
        String psz1,   // LPCSTR
        String psz2,   // LPCSTR
        boolean fIgnoreSlash   // BOOL
    );
}
@[Link("shlwapi")]
lib LibSHLWAPI
  fun UrlCompareA = UrlCompareA(
    psz1 : UInt8*,   # LPCSTR
    psz2 : UInt8*,   # LPCSTR
    fIgnoreSlash : Int32   # BOOL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef UrlCompareANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32);
typedef UrlCompareADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int);
final UrlCompareA = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<UrlCompareANative, UrlCompareADart>('UrlCompareA');
// psz1 : LPCSTR -> Pointer<Utf8>
// psz2 : LPCSTR -> Pointer<Utf8>
// fIgnoreSlash : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function UrlCompareA(
  psz1: PAnsiChar;   // LPCSTR
  psz2: PAnsiChar;   // LPCSTR
  fIgnoreSlash: BOOL   // BOOL
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'UrlCompareA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "UrlCompareA"
  c_UrlCompareA :: CString -> CString -> CInt -> IO Int32
-- psz1 : LPCSTR -> CString
-- psz2 : LPCSTR -> CString
-- fIgnoreSlash : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let urlcomparea =
  foreign "UrlCompareA"
    (string @-> string @-> int32_t @-> returning int32_t)
(* psz1 : LPCSTR -> string *)
(* psz2 : LPCSTR -> string *)
(* fIgnoreSlash : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("UrlCompareA" url-compare-a :convention :stdcall) :int32
  (psz1 :string)   ; LPCSTR
  (psz2 :string)   ; LPCSTR
  (f-ignore-slash :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $UrlCompareA = Win32::API::More->new('SHLWAPI',
    'int UrlCompareA(LPCSTR psz1, LPCSTR psz2, BOOL fIgnoreSlash)');
# my $ret = $UrlCompareA->Call($psz1, $psz2, $fIgnoreSlash);
# psz1 : LPCSTR -> LPCSTR
# psz2 : LPCSTR -> LPCSTR
# fIgnoreSlash : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目