ホーム › System.Search › SQLBrowseConnect
SQLBrowseConnect
関数接続に必要な属性を反復的に取得しながら接続する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLBrowseConnect(
void* hdbc,
BYTE* szConnStrIn,
SHORT cchConnStrIn,
BYTE* szConnStrOut, // optional
SHORT cchConnStrOutMax,
SHORT* pcchConnStrOut // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdbc | void* | inout | 接続を確立する接続ハンドル。 |
| szConnStrIn | BYTE* | in | 入力接続文字列。段階的に属性を指定する。ANSI文字列。 |
| cchConnStrIn | SHORT | in | szConnStrInの文字数。SQL_NTSでNUL終端を示す。 |
| szConnStrOut | BYTE* | outoptional | 次に必要な属性を示す出力接続文字列を受け取るバッファ。 |
| cchConnStrOutMax | SHORT | in | szConnStrOutバッファの文字数長。 |
| pcchConnStrOut | SHORT* | outoptional | 出力接続文字列の実際の文字数を受け取るポインタ。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLBrowseConnect(
void* hdbc,
BYTE* szConnStrIn,
SHORT cchConnStrIn,
BYTE* szConnStrOut, // optional
SHORT cchConnStrOutMax,
SHORT* pcchConnStrOut // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLBrowseConnect(
IntPtr hdbc, // void* in/out
IntPtr szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
IntPtr szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
IntPtr pcchConnStrOut // SHORT* optional, out
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLBrowseConnect(
hdbc As IntPtr, ' void* in/out
szConnStrIn As IntPtr, ' BYTE*
cchConnStrIn As Short, ' SHORT
szConnStrOut As IntPtr, ' BYTE* optional, out
cchConnStrOutMax As Short, ' SHORT
pcchConnStrOut As IntPtr ' SHORT* optional, out
) As Short
End Function' hdbc : void* in/out
' szConnStrIn : BYTE*
' cchConnStrIn : SHORT
' szConnStrOut : BYTE* optional, out
' cchConnStrOutMax : SHORT
' pcchConnStrOut : SHORT* optional, out
Declare PtrSafe Function SQLBrowseConnect Lib "odbc32" ( _
ByVal hdbc As LongPtr, _
ByVal szConnStrIn As LongPtr, _
ByVal cchConnStrIn As Integer, _
ByVal szConnStrOut As LongPtr, _
ByVal cchConnStrOutMax As Integer, _
ByVal pcchConnStrOut As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLBrowseConnect = ctypes.windll.odbc32.SQLBrowseConnect
SQLBrowseConnect.restype = ctypes.c_short
SQLBrowseConnect.argtypes = [
ctypes.POINTER(None), # hdbc : void* in/out
ctypes.POINTER(ctypes.c_ubyte), # szConnStrIn : BYTE*
ctypes.c_short, # cchConnStrIn : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szConnStrOut : BYTE* 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')
SQLBrowseConnect = Fiddle::Function.new(
lib['SQLBrowseConnect'],
[
Fiddle::TYPE_VOIDP, # hdbc : void* in/out
Fiddle::TYPE_VOIDP, # szConnStrIn : BYTE*
Fiddle::TYPE_SHORT, # cchConnStrIn : SHORT
Fiddle::TYPE_VOIDP, # szConnStrOut : BYTE* optional, out
Fiddle::TYPE_SHORT, # cchConnStrOutMax : SHORT
Fiddle::TYPE_VOIDP, # pcchConnStrOut : SHORT* optional, out
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLBrowseConnect(
hdbc: *mut (), // void* in/out
szConnStrIn: *mut u8, // BYTE*
cchConnStrIn: i16, // SHORT
szConnStrOut: *mut u8, // BYTE* 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.Ansi)]
public static extern short SQLBrowseConnect(IntPtr hdbc, IntPtr szConnStrIn, short cchConnStrIn, IntPtr szConnStrOut, short cchConnStrOutMax, IntPtr pcchConnStrOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLBrowseConnect' -Namespace Win32 -PassThru
# $api::SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)#uselib "ODBC32.dll"
#func global SQLBrowseConnect "SQLBrowseConnect" sptr, sptr, sptr, sptr, sptr, sptr
; SQLBrowseConnect hdbc, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut) ; 戻り値は stat
; hdbc : void* in/out -> "sptr"
; szConnStrIn : BYTE* -> "sptr"
; cchConnStrIn : SHORT -> "sptr"
; szConnStrOut : BYTE* optional, out -> "sptr"
; cchConnStrOutMax : SHORT -> "sptr"
; pcchConnStrOut : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLBrowseConnect "SQLBrowseConnect" sptr, var, int, var, int, var ; res = SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut) ; hdbc : void* in/out -> "sptr" ; szConnStrIn : BYTE* -> "var" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "var" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLBrowseConnect "SQLBrowseConnect" sptr, sptr, int, sptr, int, sptr ; res = SQLBrowseConnect(hdbc, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut)) ; hdbc : void* in/out -> "sptr" ; szConnStrIn : BYTE* -> "sptr" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "sptr" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLBrowseConnect(void* hdbc, BYTE* szConnStrIn, SHORT cchConnStrIn, BYTE* szConnStrOut, SHORT cchConnStrOutMax, SHORT* pcchConnStrOut) #uselib "ODBC32.dll" #cfunc global SQLBrowseConnect "SQLBrowseConnect" intptr, var, int, var, int, var ; res = SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut) ; hdbc : void* in/out -> "intptr" ; szConnStrIn : BYTE* -> "var" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "var" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLBrowseConnect(void* hdbc, BYTE* szConnStrIn, SHORT cchConnStrIn, BYTE* szConnStrOut, SHORT cchConnStrOutMax, SHORT* pcchConnStrOut) #uselib "ODBC32.dll" #cfunc global SQLBrowseConnect "SQLBrowseConnect" intptr, intptr, int, intptr, int, intptr ; res = SQLBrowseConnect(hdbc, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut)) ; hdbc : void* in/out -> "intptr" ; szConnStrIn : BYTE* -> "intptr" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "intptr" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLBrowseConnect = odbc32.NewProc("SQLBrowseConnect")
)
// hdbc (void* in/out), szConnStrIn (BYTE*), cchConnStrIn (SHORT), szConnStrOut (BYTE* optional, out), cchConnStrOutMax (SHORT), pcchConnStrOut (SHORT* optional, out)
r1, _, err := procSQLBrowseConnect.Call(
uintptr(hdbc),
uintptr(szConnStrIn),
uintptr(cchConnStrIn),
uintptr(szConnStrOut),
uintptr(cchConnStrOutMax),
uintptr(pcchConnStrOut),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLBrowseConnect(
hdbc: Pointer; // void* in/out
szConnStrIn: Pointer; // BYTE*
cchConnStrIn: Smallint; // SHORT
szConnStrOut: Pointer; // BYTE* optional, out
cchConnStrOutMax: Smallint; // SHORT
pcchConnStrOut: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLBrowseConnect';result := DllCall("ODBC32\SQLBrowseConnect"
, "Ptr", hdbc ; void* in/out
, "Ptr", szConnStrIn ; BYTE*
, "Short", cchConnStrIn ; SHORT
, "Ptr", szConnStrOut ; BYTE* optional, out
, "Short", cchConnStrOutMax ; SHORT
, "Ptr", pcchConnStrOut ; SHORT* optional, out
, "Short") ; return: SHORT●SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut) = DLL("ODBC32.dll", "int SQLBrowseConnect(void*, void*, int, void*, int, void*)")
# 呼び出し: SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
# hdbc : void* in/out -> "void*"
# szConnStrIn : BYTE* -> "void*"
# cchConnStrIn : SHORT -> "int"
# szConnStrOut : BYTE* optional, out -> "void*"
# cchConnStrOutMax : SHORT -> "int"
# pcchConnStrOut : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLBrowseConnect(
hdbc: ?*anyopaque, // void* in/out
szConnStrIn: [*c]u8, // BYTE*
cchConnStrIn: i16, // SHORT
szConnStrOut: [*c]u8, // BYTE* optional, out
cchConnStrOutMax: i16, // SHORT
pcchConnStrOut: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;proc SQLBrowseConnect(
hdbc: pointer, # void* in/out
szConnStrIn: ptr uint8, # BYTE*
cchConnStrIn: int16, # SHORT
szConnStrOut: ptr uint8, # BYTE* optional, out
cchConnStrOutMax: int16, # SHORT
pcchConnStrOut: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLBrowseConnect", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLBrowseConnect(
void* hdbc, // void* in/out
ubyte* szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
ubyte* szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
short* pcchConnStrOut // SHORT* optional, out
);ccall((:SQLBrowseConnect, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{Int16}),
hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
# hdbc : void* in/out -> Ptr{Cvoid}
# szConnStrIn : BYTE* -> Ptr{UInt8}
# cchConnStrIn : SHORT -> Int16
# szConnStrOut : BYTE* optional, out -> Ptr{UInt8}
# cchConnStrOutMax : SHORT -> Int16
# pcchConnStrOut : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLBrowseConnect(
void* hdbc,
uint8_t* szConnStrIn,
int16_t cchConnStrIn,
uint8_t* szConnStrOut,
int16_t cchConnStrOutMax,
int16_t* pcchConnStrOut);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
-- hdbc : void* in/out
-- szConnStrIn : BYTE*
-- cchConnStrIn : SHORT
-- szConnStrOut : BYTE* optional, out
-- cchConnStrOutMax : SHORT
-- pcchConnStrOut : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLBrowseConnect = lib.func('__stdcall', 'SQLBrowseConnect', 'int16_t', ['void *', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'int16_t *']);
// SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
// hdbc : void* in/out -> 'void *'
// szConnStrIn : BYTE* -> 'uint8_t *'
// cchConnStrIn : SHORT -> 'int16_t'
// szConnStrOut : BYTE* optional, out -> 'uint8_t *'
// cchConnStrOutMax : SHORT -> 'int16_t'
// pcchConnStrOut : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLBrowseConnect: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut)
// hdbc : void* in/out -> "pointer"
// szConnStrIn : BYTE* -> "pointer"
// cchConnStrIn : SHORT -> "i16"
// szConnStrOut : BYTE* optional, out -> "pointer"
// cchConnStrOutMax : SHORT -> "i16"
// pcchConnStrOut : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLBrowseConnect(
void* hdbc,
uint8_t* szConnStrIn,
int16_t cchConnStrIn,
uint8_t* szConnStrOut,
int16_t cchConnStrOutMax,
int16_t* pcchConnStrOut);
C, "ODBC32.dll");
// $ffi->SQLBrowseConnect(hdbc, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut);
// hdbc : void* in/out
// szConnStrIn : BYTE*
// cchConnStrIn : SHORT
// szConnStrOut : BYTE* 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.ASCII_OPTIONS);
short SQLBrowseConnect(
Pointer hdbc, // void* in/out
byte[] szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
byte[] szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
ShortByReference pcchConnStrOut // SHORT* optional, out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLBrowseConnect = SQLBrowseConnect(
hdbc : Void*, # void* in/out
szConnStrIn : UInt8*, # BYTE*
cchConnStrIn : Int16, # SHORT
szConnStrOut : UInt8*, # BYTE* 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 SQLBrowseConnectNative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Int16>);
typedef SQLBrowseConnectDart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Int16>);
final SQLBrowseConnect = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLBrowseConnectNative, SQLBrowseConnectDart>('SQLBrowseConnect');
// hdbc : void* in/out -> Pointer<Void>
// szConnStrIn : BYTE* -> Pointer<Uint8>
// cchConnStrIn : SHORT -> Int16
// szConnStrOut : BYTE* optional, out -> Pointer<Uint8>
// cchConnStrOutMax : SHORT -> Int16
// pcchConnStrOut : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLBrowseConnect(
hdbc: Pointer; // void* in/out
szConnStrIn: Pointer; // BYTE*
cchConnStrIn: Smallint; // SHORT
szConnStrOut: Pointer; // BYTE* optional, out
cchConnStrOutMax: Smallint; // SHORT
pcchConnStrOut: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLBrowseConnect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLBrowseConnect"
c_SQLBrowseConnect :: Ptr () -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- szConnStrIn : BYTE* -> Ptr Word8
-- cchConnStrIn : SHORT -> Int16
-- szConnStrOut : BYTE* optional, out -> Ptr Word8
-- cchConnStrOutMax : SHORT -> Int16
-- pcchConnStrOut : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlbrowseconnect =
foreign "SQLBrowseConnect"
((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) *)
(* cchConnStrIn : SHORT -> int16_t *)
(* szConnStrOut : BYTE* optional, out -> (ptr uint8_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 ("SQLBrowseConnect" sqlbrowse-connect :convention :stdcall) :int16
(hdbc :pointer) ; void* in/out
(sz-conn-str-in :pointer) ; BYTE*
(cch-conn-str-in :int16) ; SHORT
(sz-conn-str-out :pointer) ; BYTE* 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 $SQLBrowseConnect = Win32::API::More->new('ODBC32',
'short SQLBrowseConnect(LPVOID hdbc, LPVOID szConnStrIn, short cchConnStrIn, LPVOID szConnStrOut, short cchConnStrOutMax, LPVOID pcchConnStrOut)');
# my $ret = $SQLBrowseConnect->Call($hdbc, $szConnStrIn, $cchConnStrIn, $szConnStrOut, $cchConnStrOutMax, $pcchConnStrOut);
# hdbc : void* in/out -> LPVOID
# szConnStrIn : BYTE* -> LPVOID
# cchConnStrIn : SHORT -> short
# szConnStrOut : BYTE* optional, out -> LPVOID
# cchConnStrOutMax : SHORT -> short
# pcchConnStrOut : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLBrowseConnectA (ANSI版) — 接続に必要な属性を段階的に取得しながら接続する。
- f SQLBrowseConnectW (Unicode版) — 接続属性を反復取得しながらデータソースに接続する(Unicode)。