Win32 API 日本語リファレンス
ホームSystem.Search › SQLBrowseConnectW

SQLBrowseConnectW

関数
接続属性を反復取得しながらデータソースに接続する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLBrowseConnectW(
    void* hdbc,
    WORD* szConnStrIn,
    SHORT cchConnStrIn,
    WORD* szConnStrOut,   // optional
    SHORT cchConnStrOutMax,
    SHORT* pcchConnStrOut   // optional
);

パラメーター

名前方向説明
hdbcvoid*inout接続を確立する接続ハンドル。
szConnStrInWORD*in入力接続文字列。段階的に属性を指定する。Unicode文字列。
cchConnStrInSHORTinszConnStrInの文字数。SQL_NTSでNUL終端を示す。
szConnStrOutWORD*outoptional次に必要な属性を示す出力接続文字列を受け取るバッファ。Unicode。
cchConnStrOutMaxSHORTinszConnStrOutバッファの文字数長。
pcchConnStrOutSHORT*outoptional出力接続文字列の実際の文字数を受け取るポインタ。NULL可。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLBrowseConnectW(
    void* hdbc,
    WORD* szConnStrIn,
    SHORT cchConnStrIn,
    WORD* szConnStrOut,   // optional
    SHORT cchConnStrOutMax,
    SHORT* pcchConnStrOut   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLBrowseConnectW(
    IntPtr hdbc,   // void* in/out
    ref ushort szConnStrIn,   // WORD*
    short cchConnStrIn,   // SHORT
    IntPtr szConnStrOut,   // WORD* optional, out
    short cchConnStrOutMax,   // SHORT
    IntPtr pcchConnStrOut   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLBrowseConnectW(
    hdbc As IntPtr,   ' void* in/out
    ByRef szConnStrIn As UShort,   ' WORD*
    cchConnStrIn As Short,   ' SHORT
    szConnStrOut As IntPtr,   ' WORD* optional, out
    cchConnStrOutMax As Short,   ' SHORT
    pcchConnStrOut As IntPtr   ' SHORT* optional, out
) As Short
End Function
' hdbc : void* in/out
' szConnStrIn : WORD*
' cchConnStrIn : SHORT
' szConnStrOut : WORD* optional, out
' cchConnStrOutMax : SHORT
' pcchConnStrOut : SHORT* optional, out
Declare PtrSafe Function SQLBrowseConnectW Lib "odbc32" ( _
    ByVal hdbc As LongPtr, _
    ByRef szConnStrIn As Integer, _
    ByVal cchConnStrIn As Integer, _
    ByVal szConnStrOut As LongPtr, _
    ByVal cchConnStrOutMax As Integer, _
    ByVal pcchConnStrOut As LongPtr) As Integer
' 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

SQLBrowseConnectW = ctypes.windll.odbc32.SQLBrowseConnectW
SQLBrowseConnectW.restype = ctypes.c_short
SQLBrowseConnectW.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szConnStrIn : WORD*
    ctypes.c_short,  # cchConnStrIn : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szConnStrOut : WORD* optional, out
    ctypes.c_short,  # cchConnStrOutMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcchConnStrOut : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLBrowseConnectW = Fiddle::Function.new(
  lib['SQLBrowseConnectW'],
  [
    Fiddle::TYPE_VOIDP,  # hdbc : void* in/out
    Fiddle::TYPE_VOIDP,  # szConnStrIn : WORD*
    Fiddle::TYPE_SHORT,  # cchConnStrIn : SHORT
    Fiddle::TYPE_VOIDP,  # szConnStrOut : WORD* optional, out
    Fiddle::TYPE_SHORT,  # cchConnStrOutMax : SHORT
    Fiddle::TYPE_VOIDP,  # pcchConnStrOut : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "odbc32")]
extern "system" {
    fn SQLBrowseConnectW(
        hdbc: *mut (),  // void* in/out
        szConnStrIn: *mut u16,  // WORD*
        cchConnStrIn: i16,  // SHORT
        szConnStrOut: *mut u16,  // WORD* optional, out
        cchConnStrOutMax: i16,  // SHORT
        pcchConnStrOut: *mut i16  // SHORT* optional, out
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLBrowseConnectW(IntPtr hdbc, ref ushort szConnStrIn, short cchConnStrIn, IntPtr szConnStrOut, short cchConnStrOutMax, IntPtr pcchConnStrOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLBrowseConnectW' -Namespace Win32 -PassThru
# $api::SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
#uselib "ODBC32.dll"
#func global SQLBrowseConnectW "SQLBrowseConnectW" wptr, wptr, wptr, wptr, wptr, wptr
; SQLBrowseConnectW hdbc, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut)   ; 戻り値は stat
; hdbc : void* in/out -> "wptr"
; szConnStrIn : WORD* -> "wptr"
; cchConnStrIn : SHORT -> "wptr"
; szConnStrOut : WORD* optional, out -> "wptr"
; cchConnStrOutMax : SHORT -> "wptr"
; pcchConnStrOut : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLBrowseConnectW "SQLBrowseConnectW" sptr, var, int, var, int, var
; res = SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
; hdbc : void* in/out -> "sptr"
; szConnStrIn : WORD* -> "var"
; cchConnStrIn : SHORT -> "int"
; szConnStrOut : WORD* optional, out -> "var"
; cchConnStrOutMax : SHORT -> "int"
; pcchConnStrOut : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLBrowseConnectW(void* hdbc, WORD* szConnStrIn, SHORT cchConnStrIn, WORD* szConnStrOut, SHORT cchConnStrOutMax, SHORT* pcchConnStrOut)
#uselib "ODBC32.dll"
#cfunc global SQLBrowseConnectW "SQLBrowseConnectW" intptr, var, int, var, int, var
; res = SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
; hdbc : void* in/out -> "intptr"
; szConnStrIn : WORD* -> "var"
; cchConnStrIn : SHORT -> "int"
; szConnStrOut : WORD* optional, out -> "var"
; cchConnStrOutMax : SHORT -> "int"
; pcchConnStrOut : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLBrowseConnectW = odbc32.NewProc("SQLBrowseConnectW")
)

// hdbc (void* in/out), szConnStrIn (WORD*), cchConnStrIn (SHORT), szConnStrOut (WORD* optional, out), cchConnStrOutMax (SHORT), pcchConnStrOut (SHORT* optional, out)
r1, _, err := procSQLBrowseConnectW.Call(
	uintptr(hdbc),
	uintptr(szConnStrIn),
	uintptr(cchConnStrIn),
	uintptr(szConnStrOut),
	uintptr(cchConnStrOutMax),
	uintptr(pcchConnStrOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLBrowseConnectW(
  hdbc: Pointer;   // void* in/out
  szConnStrIn: Pointer;   // WORD*
  cchConnStrIn: Smallint;   // SHORT
  szConnStrOut: Pointer;   // WORD* optional, out
  cchConnStrOutMax: Smallint;   // SHORT
  pcchConnStrOut: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLBrowseConnectW';
result := DllCall("ODBC32\SQLBrowseConnectW"
    , "Ptr", hdbc   ; void* in/out
    , "Ptr", szConnStrIn   ; WORD*
    , "Short", cchConnStrIn   ; SHORT
    , "Ptr", szConnStrOut   ; WORD* optional, out
    , "Short", cchConnStrOutMax   ; SHORT
    , "Ptr", pcchConnStrOut   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut) = DLL("ODBC32.dll", "int SQLBrowseConnectW(void*, void*, int, void*, int, void*)")
# 呼び出し: SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
# hdbc : void* in/out -> "void*"
# szConnStrIn : WORD* -> "void*"
# cchConnStrIn : SHORT -> "int"
# szConnStrOut : WORD* optional, out -> "void*"
# cchConnStrOutMax : SHORT -> "int"
# pcchConnStrOut : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "odbc32" fn SQLBrowseConnectW(
    hdbc: ?*anyopaque, // void* in/out
    szConnStrIn: [*c]u16, // WORD*
    cchConnStrIn: i16, // SHORT
    szConnStrOut: [*c]u16, // WORD* optional, out
    cchConnStrOutMax: i16, // SHORT
    pcchConnStrOut: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SQLBrowseConnectW(
    hdbc: pointer,  # void* in/out
    szConnStrIn: ptr uint16,  # WORD*
    cchConnStrIn: int16,  # SHORT
    szConnStrOut: ptr uint16,  # WORD* optional, out
    cchConnStrOutMax: int16,  # SHORT
    pcchConnStrOut: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLBrowseConnectW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "odbc32");
extern(Windows)
short SQLBrowseConnectW(
    void* hdbc,   // void* in/out
    ushort* szConnStrIn,   // WORD*
    short cchConnStrIn,   // SHORT
    ushort* szConnStrOut,   // WORD* optional, out
    short cchConnStrOutMax,   // SHORT
    short* pcchConnStrOut   // SHORT* optional, out
);
ccall((:SQLBrowseConnectW, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt16}, Int16, Ptr{UInt16}, Int16, Ptr{Int16}),
      hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
# hdbc : void* in/out -> Ptr{Cvoid}
# szConnStrIn : WORD* -> Ptr{UInt16}
# cchConnStrIn : SHORT -> Int16
# szConnStrOut : WORD* optional, out -> Ptr{UInt16}
# cchConnStrOutMax : SHORT -> Int16
# pcchConnStrOut : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLBrowseConnectW(
    void* hdbc,
    uint16_t* szConnStrIn,
    int16_t cchConnStrIn,
    uint16_t* szConnStrOut,
    int16_t cchConnStrOutMax,
    int16_t* pcchConnStrOut);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
-- hdbc : void* in/out
-- szConnStrIn : WORD*
-- cchConnStrIn : SHORT
-- szConnStrOut : WORD* optional, out
-- cchConnStrOutMax : SHORT
-- pcchConnStrOut : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLBrowseConnectW = lib.func('__stdcall', 'SQLBrowseConnectW', 'int16_t', ['void *', 'uint16_t *', 'int16_t', 'uint16_t *', 'int16_t', 'int16_t *']);
// SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
// hdbc : void* in/out -> 'void *'
// szConnStrIn : WORD* -> 'uint16_t *'
// cchConnStrIn : SHORT -> 'int16_t'
// szConnStrOut : WORD* optional, out -> 'uint16_t *'
// cchConnStrOutMax : SHORT -> 'int16_t'
// pcchConnStrOut : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLBrowseConnectW: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
// hdbc : void* in/out -> "pointer"
// szConnStrIn : WORD* -> "pointer"
// cchConnStrIn : SHORT -> "i16"
// szConnStrOut : WORD* optional, out -> "pointer"
// cchConnStrOutMax : SHORT -> "i16"
// pcchConnStrOut : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLBrowseConnectW(
    void* hdbc,
    uint16_t* szConnStrIn,
    int16_t cchConnStrIn,
    uint16_t* szConnStrOut,
    int16_t cchConnStrOutMax,
    int16_t* pcchConnStrOut);
C, "ODBC32.dll");
// $ffi->SQLBrowseConnectW(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut);
// hdbc : void* in/out
// szConnStrIn : WORD*
// cchConnStrIn : SHORT
// szConnStrOut : WORD* optional, out
// cchConnStrOutMax : SHORT
// pcchConnStrOut : SHORT* optional, out
// 構造体/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 Odbc32 extends StdCallLibrary {
    Odbc32 INSTANCE = Native.load("odbc32", Odbc32.class, W32APIOptions.UNICODE_OPTIONS);
    short SQLBrowseConnectW(
        Pointer hdbc,   // void* in/out
        ShortByReference szConnStrIn,   // WORD*
        short cchConnStrIn,   // SHORT
        ShortByReference szConnStrOut,   // WORD* optional, out
        short cchConnStrOutMax,   // SHORT
        ShortByReference pcchConnStrOut   // SHORT* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("odbc32")]
lib LibODBC32
  fun SQLBrowseConnectW = SQLBrowseConnectW(
    hdbc : Void*,   # void* in/out
    szConnStrIn : UInt16*,   # WORD*
    cchConnStrIn : Int16,   # SHORT
    szConnStrOut : UInt16*,   # WORD* optional, out
    cchConnStrOutMax : Int16,   # SHORT
    pcchConnStrOut : Int16*   # SHORT* optional, out
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLBrowseConnectWNative = Int16 Function(Pointer<Void>, Pointer<Uint16>, Int16, Pointer<Uint16>, Int16, Pointer<Int16>);
typedef SQLBrowseConnectWDart = int Function(Pointer<Void>, Pointer<Uint16>, int, Pointer<Uint16>, int, Pointer<Int16>);
final SQLBrowseConnectW = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLBrowseConnectWNative, SQLBrowseConnectWDart>('SQLBrowseConnectW');
// hdbc : void* in/out -> Pointer<Void>
// szConnStrIn : WORD* -> Pointer<Uint16>
// cchConnStrIn : SHORT -> Int16
// szConnStrOut : WORD* optional, out -> Pointer<Uint16>
// cchConnStrOutMax : SHORT -> Int16
// pcchConnStrOut : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLBrowseConnectW(
  hdbc: Pointer;   // void* in/out
  szConnStrIn: Pointer;   // WORD*
  cchConnStrIn: Smallint;   // SHORT
  szConnStrOut: Pointer;   // WORD* optional, out
  cchConnStrOutMax: Smallint;   // SHORT
  pcchConnStrOut: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLBrowseConnectW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLBrowseConnectW"
  c_SQLBrowseConnectW :: Ptr () -> Ptr Word16 -> Int16 -> Ptr Word16 -> Int16 -> Ptr Int16 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- szConnStrIn : WORD* -> Ptr Word16
-- cchConnStrIn : SHORT -> Int16
-- szConnStrOut : WORD* optional, out -> Ptr Word16
-- cchConnStrOutMax : SHORT -> Int16
-- pcchConnStrOut : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlbrowseconnectw =
  foreign "SQLBrowseConnectW"
    ((ptr void) @-> (ptr uint16_t) @-> int16_t @-> (ptr uint16_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* szConnStrIn : WORD* -> (ptr uint16_t) *)
(* cchConnStrIn : SHORT -> int16_t *)
(* szConnStrOut : WORD* optional, out -> (ptr uint16_t) *)
(* cchConnStrOutMax : SHORT -> int16_t *)
(* pcchConnStrOut : SHORT* optional, out -> (ptr int16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLBrowseConnectW" sqlbrowse-connect-w :convention :stdcall) :int16
  (hdbc :pointer)   ; void* in/out
  (sz-conn-str-in :pointer)   ; WORD*
  (cch-conn-str-in :int16)   ; SHORT
  (sz-conn-str-out :pointer)   ; WORD* optional, out
  (cch-conn-str-out-max :int16)   ; SHORT
  (pcch-conn-str-out :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLBrowseConnectW = Win32::API::More->new('ODBC32',
    'short SQLBrowseConnectW(LPVOID hdbc, LPVOID szConnStrIn, short cchConnStrIn, LPVOID szConnStrOut, short cchConnStrOutMax, LPVOID pcchConnStrOut)');
# my $ret = $SQLBrowseConnectW->Call($hdbc, $szConnStrIn, $cchConnStrIn, $szConnStrOut, $cchConnStrOutMax, $pcchConnStrOut);
# hdbc : void* in/out -> LPVOID
# szConnStrIn : WORD* -> LPVOID
# cchConnStrIn : SHORT -> short
# szConnStrOut : WORD* optional, out -> LPVOID
# cchConnStrOutMax : SHORT -> short
# pcchConnStrOut : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い