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

SQLBrowseConnectA

関数
接続に必要な属性を段階的に取得しながら接続する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLBrowseConnectA(
    void* hdbc,
    BYTE* szConnStrIn,
    SHORT cbConnStrIn,
    BYTE* szConnStrOut,   // optional
    SHORT cbConnStrOutMax,
    SHORT* pcbConnStrOut   // optional
);

パラメーター

名前方向説明
hdbcvoid*inoutODBCの接続ハンドル。段階的接続を行う対象。
szConnStrInBYTE*in現段階で入力する接続文字列(部分的でも可)。
cbConnStrInSHORTinszConnStrInの文字数。SQL_NTSでNUL終端とみなす。
szConnStrOutBYTE*outoptional次に必要な属性を示す接続文字列を受け取るバッファ。出力用。
cbConnStrOutMaxSHORTinszConnStrOutバッファのバイト長。
pcbConnStrOutSHORT*outoptional実際に返された接続文字列のバイト長を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLBrowseConnectA(
    void* hdbc,
    BYTE* szConnStrIn,
    SHORT cbConnStrIn,
    BYTE* szConnStrOut,   // optional
    SHORT cbConnStrOutMax,
    SHORT* pcbConnStrOut   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLBrowseConnectA(
    IntPtr hdbc,   // void* in/out
    IntPtr szConnStrIn,   // BYTE*
    short cbConnStrIn,   // SHORT
    IntPtr szConnStrOut,   // BYTE* optional, out
    short cbConnStrOutMax,   // SHORT
    IntPtr pcbConnStrOut   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLBrowseConnectA(
    hdbc As IntPtr,   ' void* in/out
    szConnStrIn As IntPtr,   ' BYTE*
    cbConnStrIn As Short,   ' SHORT
    szConnStrOut As IntPtr,   ' BYTE* optional, out
    cbConnStrOutMax As Short,   ' SHORT
    pcbConnStrOut As IntPtr   ' SHORT* optional, out
) As Short
End Function
' hdbc : void* in/out
' szConnStrIn : BYTE*
' cbConnStrIn : SHORT
' szConnStrOut : BYTE* optional, out
' cbConnStrOutMax : SHORT
' pcbConnStrOut : SHORT* optional, out
Declare PtrSafe Function SQLBrowseConnectA Lib "odbc32" ( _
    ByVal hdbc As LongPtr, _
    ByVal szConnStrIn As LongPtr, _
    ByVal cbConnStrIn As Integer, _
    ByVal szConnStrOut As LongPtr, _
    ByVal cbConnStrOutMax As Integer, _
    ByVal pcbConnStrOut As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLBrowseConnectA = ctypes.windll.odbc32.SQLBrowseConnectA
SQLBrowseConnectA.restype = ctypes.c_short
SQLBrowseConnectA.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # szConnStrIn : BYTE*
    ctypes.c_short,  # cbConnStrIn : SHORT
    ctypes.POINTER(ctypes.c_ubyte),  # szConnStrOut : BYTE* optional, out
    ctypes.c_short,  # cbConnStrOutMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbConnStrOut : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLBrowseConnectA = odbc32.NewProc("SQLBrowseConnectA")
)

// hdbc (void* in/out), szConnStrIn (BYTE*), cbConnStrIn (SHORT), szConnStrOut (BYTE* optional, out), cbConnStrOutMax (SHORT), pcbConnStrOut (SHORT* optional, out)
r1, _, err := procSQLBrowseConnectA.Call(
	uintptr(hdbc),
	uintptr(szConnStrIn),
	uintptr(cbConnStrIn),
	uintptr(szConnStrOut),
	uintptr(cbConnStrOutMax),
	uintptr(pcbConnStrOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLBrowseConnectA(
  hdbc: Pointer;   // void* in/out
  szConnStrIn: Pointer;   // BYTE*
  cbConnStrIn: Smallint;   // SHORT
  szConnStrOut: Pointer;   // BYTE* optional, out
  cbConnStrOutMax: Smallint;   // SHORT
  pcbConnStrOut: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLBrowseConnectA';
result := DllCall("ODBC32\SQLBrowseConnectA"
    , "Ptr", hdbc   ; void* in/out
    , "Ptr", szConnStrIn   ; BYTE*
    , "Short", cbConnStrIn   ; SHORT
    , "Ptr", szConnStrOut   ; BYTE* optional, out
    , "Short", cbConnStrOutMax   ; SHORT
    , "Ptr", pcbConnStrOut   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut) = DLL("ODBC32.dll", "int SQLBrowseConnectA(void*, void*, int, void*, int, void*)")
# 呼び出し: SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)
# hdbc : void* in/out -> "void*"
# szConnStrIn : BYTE* -> "void*"
# cbConnStrIn : SHORT -> "int"
# szConnStrOut : BYTE* optional, out -> "void*"
# cbConnStrOutMax : SHORT -> "int"
# pcbConnStrOut : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLBrowseConnectA(
    hdbc: ?*anyopaque, // void* in/out
    szConnStrIn: [*c]u8, // BYTE*
    cbConnStrIn: i16, // SHORT
    szConnStrOut: [*c]u8, // BYTE* optional, out
    cbConnStrOutMax: i16, // SHORT
    pcbConnStrOut: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
proc SQLBrowseConnectA(
    hdbc: pointer,  # void* in/out
    szConnStrIn: ptr uint8,  # BYTE*
    cbConnStrIn: int16,  # SHORT
    szConnStrOut: ptr uint8,  # BYTE* optional, out
    cbConnStrOutMax: int16,  # SHORT
    pcbConnStrOut: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLBrowseConnectA", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLBrowseConnectA(
    void* hdbc,   // void* in/out
    ubyte* szConnStrIn,   // BYTE*
    short cbConnStrIn,   // SHORT
    ubyte* szConnStrOut,   // BYTE* optional, out
    short cbConnStrOutMax,   // SHORT
    short* pcbConnStrOut   // SHORT* optional, out
);
ccall((:SQLBrowseConnectA, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{Int16}),
      hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)
# hdbc : void* in/out -> Ptr{Cvoid}
# szConnStrIn : BYTE* -> Ptr{UInt8}
# cbConnStrIn : SHORT -> Int16
# szConnStrOut : BYTE* optional, out -> Ptr{UInt8}
# cbConnStrOutMax : SHORT -> Int16
# pcbConnStrOut : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLBrowseConnectA(
    void* hdbc,
    uint8_t* szConnStrIn,
    int16_t cbConnStrIn,
    uint8_t* szConnStrOut,
    int16_t cbConnStrOutMax,
    int16_t* pcbConnStrOut);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)
-- hdbc : void* in/out
-- szConnStrIn : BYTE*
-- cbConnStrIn : SHORT
-- szConnStrOut : BYTE* optional, out
-- cbConnStrOutMax : SHORT
-- pcbConnStrOut : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLBrowseConnectA = lib.func('__stdcall', 'SQLBrowseConnectA', 'int16_t', ['void *', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'int16_t *']);
// SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)
// hdbc : void* in/out -> 'void *'
// szConnStrIn : BYTE* -> 'uint8_t *'
// cbConnStrIn : SHORT -> 'int16_t'
// szConnStrOut : BYTE* optional, out -> 'uint8_t *'
// cbConnStrOutMax : SHORT -> 'int16_t'
// pcbConnStrOut : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLBrowseConnectA: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)
// hdbc : void* in/out -> "pointer"
// szConnStrIn : BYTE* -> "pointer"
// cbConnStrIn : SHORT -> "i16"
// szConnStrOut : BYTE* optional, out -> "pointer"
// cbConnStrOutMax : SHORT -> "i16"
// pcbConnStrOut : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLBrowseConnectA(
    void* hdbc,
    uint8_t* szConnStrIn,
    int16_t cbConnStrIn,
    uint8_t* szConnStrOut,
    int16_t cbConnStrOutMax,
    int16_t* pcbConnStrOut);
C, "ODBC32.dll");
// $ffi->SQLBrowseConnectA(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut);
// hdbc : void* in/out
// szConnStrIn : BYTE*
// cbConnStrIn : SHORT
// szConnStrOut : BYTE* optional, out
// cbConnStrOutMax : SHORT
// pcbConnStrOut : 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.ASCII_OPTIONS);
    short SQLBrowseConnectA(
        Pointer hdbc,   // void* in/out
        byte[] szConnStrIn,   // BYTE*
        short cbConnStrIn,   // SHORT
        byte[] szConnStrOut,   // BYTE* optional, out
        short cbConnStrOutMax,   // SHORT
        ShortByReference pcbConnStrOut   // SHORT* optional, out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLBrowseConnectA = SQLBrowseConnectA(
    hdbc : Void*,   # void* in/out
    szConnStrIn : UInt8*,   # BYTE*
    cbConnStrIn : Int16,   # SHORT
    szConnStrOut : UInt8*,   # BYTE* optional, out
    cbConnStrOutMax : Int16,   # SHORT
    pcbConnStrOut : 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 SQLBrowseConnectANative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Int16>);
typedef SQLBrowseConnectADart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Int16>);
final SQLBrowseConnectA = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLBrowseConnectANative, SQLBrowseConnectADart>('SQLBrowseConnectA');
// hdbc : void* in/out -> Pointer<Void>
// szConnStrIn : BYTE* -> Pointer<Uint8>
// cbConnStrIn : SHORT -> Int16
// szConnStrOut : BYTE* optional, out -> Pointer<Uint8>
// cbConnStrOutMax : SHORT -> Int16
// pcbConnStrOut : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLBrowseConnectA(
  hdbc: Pointer;   // void* in/out
  szConnStrIn: Pointer;   // BYTE*
  cbConnStrIn: Smallint;   // SHORT
  szConnStrOut: Pointer;   // BYTE* optional, out
  cbConnStrOutMax: Smallint;   // SHORT
  pcbConnStrOut: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLBrowseConnectA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLBrowseConnectA"
  c_SQLBrowseConnectA :: Ptr () -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- szConnStrIn : BYTE* -> Ptr Word8
-- cbConnStrIn : SHORT -> Int16
-- szConnStrOut : BYTE* optional, out -> Ptr Word8
-- cbConnStrOutMax : SHORT -> Int16
-- pcbConnStrOut : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlbrowseconnecta =
  foreign "SQLBrowseConnectA"
    ((ptr void) @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* szConnStrIn : BYTE* -> (ptr uint8_t) *)
(* cbConnStrIn : SHORT -> int16_t *)
(* szConnStrOut : BYTE* optional, out -> (ptr uint8_t) *)
(* cbConnStrOutMax : SHORT -> int16_t *)
(* pcbConnStrOut : 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 ("SQLBrowseConnectA" sqlbrowse-connect-a :convention :stdcall) :int16
  (hdbc :pointer)   ; void* in/out
  (sz-conn-str-in :pointer)   ; BYTE*
  (cb-conn-str-in :int16)   ; SHORT
  (sz-conn-str-out :pointer)   ; BYTE* optional, out
  (cb-conn-str-out-max :int16)   ; SHORT
  (pcb-conn-str-out :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLBrowseConnectA = Win32::API::More->new('ODBC32',
    'short SQLBrowseConnectA(LPVOID hdbc, LPVOID szConnStrIn, short cbConnStrIn, LPVOID szConnStrOut, short cbConnStrOutMax, LPVOID pcbConnStrOut)');
# my $ret = $SQLBrowseConnectA->Call($hdbc, $szConnStrIn, $cbConnStrIn, $szConnStrOut, $cbConnStrOutMax, $pcbConnStrOut);
# hdbc : void* in/out -> LPVOID
# szConnStrIn : BYTE* -> LPVOID
# cbConnStrIn : SHORT -> short
# szConnStrOut : BYTE* optional, out -> LPVOID
# cbConnStrOutMax : SHORT -> short
# pcbConnStrOut : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い