ホーム › System.Search › SQLDriverConnect
SQLDriverConnect
関数接続文字列やダイアログでデータソースに接続する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLDriverConnect(
void* hdbc,
INT_PTR hwnd,
BYTE* szConnStrIn,
SHORT cchConnStrIn,
BYTE* szConnStrOut, // optional
SHORT cchConnStrOutMax,
SHORT* pcchConnStrOut, // optional
WORD fDriverCompletion
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdbc | void* | inout | 接続を確立する接続ハンドル。 |
| hwnd | INT_PTR | in | ダイアログ表示用の親ウィンドウハンドル。表示不要ならNULL。 |
| szConnStrIn | BYTE* | in | 入力接続文字列。キーワード=値の組。ANSI文字列。 |
| cchConnStrIn | SHORT | in | szConnStrInの文字数。SQL_NTSでNUL終端を示す。 |
| szConnStrOut | BYTE* | outoptional | 完成した接続文字列を受け取るバッファ。ANSI文字列。 |
| cchConnStrOutMax | SHORT | in | szConnStrOutバッファの文字数長。 |
| pcchConnStrOut | SHORT* | outoptional | 出力接続文字列の実際の文字数を受け取るポインタ。NULL可。 |
| fDriverCompletion | WORD | in | ダイアログ表示制御。SQL_DRIVER_PROMPT/COMPLETE/NOPROMPT等。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLDriverConnect(
void* hdbc,
INT_PTR hwnd,
BYTE* szConnStrIn,
SHORT cchConnStrIn,
BYTE* szConnStrOut, // optional
SHORT cchConnStrOutMax,
SHORT* pcchConnStrOut, // optional
WORD fDriverCompletion
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLDriverConnect(
IntPtr hdbc, // void* in/out
IntPtr hwnd, // INT_PTR
IntPtr szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
IntPtr szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
IntPtr pcchConnStrOut, // SHORT* optional, out
ushort fDriverCompletion // WORD
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLDriverConnect(
hdbc As IntPtr, ' void* in/out
hwnd As IntPtr, ' INT_PTR
szConnStrIn As IntPtr, ' BYTE*
cchConnStrIn As Short, ' SHORT
szConnStrOut As IntPtr, ' BYTE* optional, out
cchConnStrOutMax As Short, ' SHORT
pcchConnStrOut As IntPtr, ' SHORT* optional, out
fDriverCompletion As UShort ' WORD
) As Short
End Function' hdbc : void* in/out
' hwnd : INT_PTR
' szConnStrIn : BYTE*
' cchConnStrIn : SHORT
' szConnStrOut : BYTE* optional, out
' cchConnStrOutMax : SHORT
' pcchConnStrOut : SHORT* optional, out
' fDriverCompletion : WORD
Declare PtrSafe Function SQLDriverConnect Lib "odbc32" ( _
ByVal hdbc As LongPtr, _
ByVal hwnd As LongPtr, _
ByVal szConnStrIn As LongPtr, _
ByVal cchConnStrIn As Integer, _
ByVal szConnStrOut As LongPtr, _
ByVal cchConnStrOutMax As Integer, _
ByVal pcchConnStrOut As LongPtr, _
ByVal fDriverCompletion As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLDriverConnect = ctypes.windll.odbc32.SQLDriverConnect
SQLDriverConnect.restype = ctypes.c_short
SQLDriverConnect.argtypes = [
ctypes.POINTER(None), # hdbc : void* in/out
ctypes.c_ssize_t, # hwnd : INT_PTR
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
ctypes.c_ushort, # fDriverCompletion : WORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLDriverConnect = Fiddle::Function.new(
lib['SQLDriverConnect'],
[
Fiddle::TYPE_VOIDP, # hdbc : void* in/out
Fiddle::TYPE_INTPTR_T, # hwnd : INT_PTR
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, # fDriverCompletion : WORD
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLDriverConnect(
hdbc: *mut (), // void* in/out
hwnd: isize, // INT_PTR
szConnStrIn: *mut u8, // BYTE*
cchConnStrIn: i16, // SHORT
szConnStrOut: *mut u8, // BYTE* optional, out
cchConnStrOutMax: i16, // SHORT
pcchConnStrOut: *mut i16, // SHORT* optional, out
fDriverCompletion: u16 // WORD
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLDriverConnect(IntPtr hdbc, IntPtr hwnd, IntPtr szConnStrIn, short cchConnStrIn, IntPtr szConnStrOut, short cchConnStrOutMax, IntPtr pcchConnStrOut, ushort fDriverCompletion);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLDriverConnect' -Namespace Win32 -PassThru
# $api::SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)#uselib "ODBC32.dll"
#func global SQLDriverConnect "SQLDriverConnect" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLDriverConnect hdbc, hwnd, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut), fDriverCompletion ; 戻り値は stat
; hdbc : void* in/out -> "sptr"
; hwnd : INT_PTR -> "sptr"
; szConnStrIn : BYTE* -> "sptr"
; cchConnStrIn : SHORT -> "sptr"
; szConnStrOut : BYTE* optional, out -> "sptr"
; cchConnStrOutMax : SHORT -> "sptr"
; pcchConnStrOut : SHORT* optional, out -> "sptr"
; fDriverCompletion : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLDriverConnect "SQLDriverConnect" sptr, sptr, var, int, var, int, var, int ; res = SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion) ; hdbc : void* in/out -> "sptr" ; hwnd : INT_PTR -> "sptr" ; szConnStrIn : BYTE* -> "var" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "var" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "var" ; fDriverCompletion : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLDriverConnect "SQLDriverConnect" sptr, sptr, sptr, int, sptr, int, sptr, int ; res = SQLDriverConnect(hdbc, hwnd, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut), fDriverCompletion) ; hdbc : void* in/out -> "sptr" ; hwnd : INT_PTR -> "sptr" ; szConnStrIn : BYTE* -> "sptr" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "sptr" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "sptr" ; fDriverCompletion : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLDriverConnect(void* hdbc, INT_PTR hwnd, BYTE* szConnStrIn, SHORT cchConnStrIn, BYTE* szConnStrOut, SHORT cchConnStrOutMax, SHORT* pcchConnStrOut, WORD fDriverCompletion) #uselib "ODBC32.dll" #cfunc global SQLDriverConnect "SQLDriverConnect" intptr, intptr, var, int, var, int, var, int ; res = SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion) ; hdbc : void* in/out -> "intptr" ; hwnd : INT_PTR -> "intptr" ; szConnStrIn : BYTE* -> "var" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "var" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "var" ; fDriverCompletion : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLDriverConnect(void* hdbc, INT_PTR hwnd, BYTE* szConnStrIn, SHORT cchConnStrIn, BYTE* szConnStrOut, SHORT cchConnStrOutMax, SHORT* pcchConnStrOut, WORD fDriverCompletion) #uselib "ODBC32.dll" #cfunc global SQLDriverConnect "SQLDriverConnect" intptr, intptr, intptr, int, intptr, int, intptr, int ; res = SQLDriverConnect(hdbc, hwnd, varptr(szConnStrIn), cchConnStrIn, varptr(szConnStrOut), cchConnStrOutMax, varptr(pcchConnStrOut), fDriverCompletion) ; hdbc : void* in/out -> "intptr" ; hwnd : INT_PTR -> "intptr" ; szConnStrIn : BYTE* -> "intptr" ; cchConnStrIn : SHORT -> "int" ; szConnStrOut : BYTE* optional, out -> "intptr" ; cchConnStrOutMax : SHORT -> "int" ; pcchConnStrOut : SHORT* optional, out -> "intptr" ; fDriverCompletion : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLDriverConnect = odbc32.NewProc("SQLDriverConnect")
)
// hdbc (void* in/out), hwnd (INT_PTR), szConnStrIn (BYTE*), cchConnStrIn (SHORT), szConnStrOut (BYTE* optional, out), cchConnStrOutMax (SHORT), pcchConnStrOut (SHORT* optional, out), fDriverCompletion (WORD)
r1, _, err := procSQLDriverConnect.Call(
uintptr(hdbc),
uintptr(hwnd),
uintptr(szConnStrIn),
uintptr(cchConnStrIn),
uintptr(szConnStrOut),
uintptr(cchConnStrOutMax),
uintptr(pcchConnStrOut),
uintptr(fDriverCompletion),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLDriverConnect(
hdbc: Pointer; // void* in/out
hwnd: NativeInt; // INT_PTR
szConnStrIn: Pointer; // BYTE*
cchConnStrIn: Smallint; // SHORT
szConnStrOut: Pointer; // BYTE* optional, out
cchConnStrOutMax: Smallint; // SHORT
pcchConnStrOut: Pointer; // SHORT* optional, out
fDriverCompletion: Word // WORD
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLDriverConnect';result := DllCall("ODBC32\SQLDriverConnect"
, "Ptr", hdbc ; void* in/out
, "Ptr", hwnd ; INT_PTR
, "Ptr", szConnStrIn ; BYTE*
, "Short", cchConnStrIn ; SHORT
, "Ptr", szConnStrOut ; BYTE* optional, out
, "Short", cchConnStrOutMax ; SHORT
, "Ptr", pcchConnStrOut ; SHORT* optional, out
, "UShort", fDriverCompletion ; WORD
, "Short") ; return: SHORT●SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion) = DLL("ODBC32.dll", "int SQLDriverConnect(void*, int, void*, int, void*, int, void*, int)")
# 呼び出し: SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)
# hdbc : void* in/out -> "void*"
# hwnd : INT_PTR -> "int"
# szConnStrIn : BYTE* -> "void*"
# cchConnStrIn : SHORT -> "int"
# szConnStrOut : BYTE* optional, out -> "void*"
# cchConnStrOutMax : SHORT -> "int"
# pcchConnStrOut : SHORT* optional, out -> "void*"
# fDriverCompletion : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLDriverConnect(
hdbc: ?*anyopaque, // void* in/out
hwnd: isize, // INT_PTR
szConnStrIn: [*c]u8, // BYTE*
cchConnStrIn: i16, // SHORT
szConnStrOut: [*c]u8, // BYTE* optional, out
cchConnStrOutMax: i16, // SHORT
pcchConnStrOut: [*c]i16, // SHORT* optional, out
fDriverCompletion: u16 // WORD
) callconv(std.os.windows.WINAPI) i16;proc SQLDriverConnect(
hdbc: pointer, # void* in/out
hwnd: int, # INT_PTR
szConnStrIn: ptr uint8, # BYTE*
cchConnStrIn: int16, # SHORT
szConnStrOut: ptr uint8, # BYTE* optional, out
cchConnStrOutMax: int16, # SHORT
pcchConnStrOut: ptr int16, # SHORT* optional, out
fDriverCompletion: uint16 # WORD
): int16 {.importc: "SQLDriverConnect", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLDriverConnect(
void* hdbc, // void* in/out
ptrdiff_t hwnd, // INT_PTR
ubyte* szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
ubyte* szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
short* pcchConnStrOut, // SHORT* optional, out
ushort fDriverCompletion // WORD
);ccall((:SQLDriverConnect, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Int, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{Int16}, UInt16),
hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)
# hdbc : void* in/out -> Ptr{Cvoid}
# hwnd : INT_PTR -> Int
# szConnStrIn : BYTE* -> Ptr{UInt8}
# cchConnStrIn : SHORT -> Int16
# szConnStrOut : BYTE* optional, out -> Ptr{UInt8}
# cchConnStrOutMax : SHORT -> Int16
# pcchConnStrOut : SHORT* optional, out -> Ptr{Int16}
# fDriverCompletion : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLDriverConnect(
void* hdbc,
intptr_t hwnd,
uint8_t* szConnStrIn,
int16_t cchConnStrIn,
uint8_t* szConnStrOut,
int16_t cchConnStrOutMax,
int16_t* pcchConnStrOut,
uint16_t fDriverCompletion);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)
-- hdbc : void* in/out
-- hwnd : INT_PTR
-- szConnStrIn : BYTE*
-- cchConnStrIn : SHORT
-- szConnStrOut : BYTE* optional, out
-- cchConnStrOutMax : SHORT
-- pcchConnStrOut : SHORT* optional, out
-- fDriverCompletion : WORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLDriverConnect = lib.func('__stdcall', 'SQLDriverConnect', 'int16_t', ['void *', 'intptr_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'int16_t *', 'uint16_t']);
// SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)
// hdbc : void* in/out -> 'void *'
// hwnd : INT_PTR -> 'intptr_t'
// szConnStrIn : BYTE* -> 'uint8_t *'
// cchConnStrIn : SHORT -> 'int16_t'
// szConnStrOut : BYTE* optional, out -> 'uint8_t *'
// cchConnStrOutMax : SHORT -> 'int16_t'
// pcchConnStrOut : SHORT* optional, out -> 'int16_t *'
// fDriverCompletion : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLDriverConnect: { parameters: ["pointer", "isize", "pointer", "i16", "pointer", "i16", "pointer", "u16"], result: "i16" },
});
// lib.symbols.SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion)
// hdbc : void* in/out -> "pointer"
// hwnd : INT_PTR -> "isize"
// szConnStrIn : BYTE* -> "pointer"
// cchConnStrIn : SHORT -> "i16"
// szConnStrOut : BYTE* optional, out -> "pointer"
// cchConnStrOutMax : SHORT -> "i16"
// pcchConnStrOut : SHORT* optional, out -> "pointer"
// fDriverCompletion : WORD -> "u16"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLDriverConnect(
void* hdbc,
intptr_t hwnd,
uint8_t* szConnStrIn,
int16_t cchConnStrIn,
uint8_t* szConnStrOut,
int16_t cchConnStrOutMax,
int16_t* pcchConnStrOut,
uint16_t fDriverCompletion);
C, "ODBC32.dll");
// $ffi->SQLDriverConnect(hdbc, hwnd, szConnStrIn, cchConnStrIn, szConnStrOut, cchConnStrOutMax, pcchConnStrOut, fDriverCompletion);
// hdbc : void* in/out
// hwnd : INT_PTR
// szConnStrIn : BYTE*
// cchConnStrIn : SHORT
// szConnStrOut : BYTE* optional, out
// cchConnStrOutMax : SHORT
// pcchConnStrOut : SHORT* optional, out
// fDriverCompletion : WORD
// 構造体/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 SQLDriverConnect(
Pointer hdbc, // void* in/out
long hwnd, // INT_PTR
byte[] szConnStrIn, // BYTE*
short cchConnStrIn, // SHORT
byte[] szConnStrOut, // BYTE* optional, out
short cchConnStrOutMax, // SHORT
ShortByReference pcchConnStrOut, // SHORT* optional, out
short fDriverCompletion // WORD
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLDriverConnect = SQLDriverConnect(
hdbc : Void*, # void* in/out
hwnd : LibC::SSizeT, # INT_PTR
szConnStrIn : UInt8*, # BYTE*
cchConnStrIn : Int16, # SHORT
szConnStrOut : UInt8*, # BYTE* optional, out
cchConnStrOutMax : Int16, # SHORT
pcchConnStrOut : Int16*, # SHORT* optional, out
fDriverCompletion : UInt16 # WORD
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLDriverConnectNative = Int16 Function(Pointer<Void>, IntPtr, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Int16>, Uint16);
typedef SQLDriverConnectDart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Int16>, int);
final SQLDriverConnect = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLDriverConnectNative, SQLDriverConnectDart>('SQLDriverConnect');
// hdbc : void* in/out -> Pointer<Void>
// hwnd : INT_PTR -> IntPtr
// szConnStrIn : BYTE* -> Pointer<Uint8>
// cchConnStrIn : SHORT -> Int16
// szConnStrOut : BYTE* optional, out -> Pointer<Uint8>
// cchConnStrOutMax : SHORT -> Int16
// pcchConnStrOut : SHORT* optional, out -> Pointer<Int16>
// fDriverCompletion : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLDriverConnect(
hdbc: Pointer; // void* in/out
hwnd: NativeInt; // INT_PTR
szConnStrIn: Pointer; // BYTE*
cchConnStrIn: Smallint; // SHORT
szConnStrOut: Pointer; // BYTE* optional, out
cchConnStrOutMax: Smallint; // SHORT
pcchConnStrOut: Pointer; // SHORT* optional, out
fDriverCompletion: Word // WORD
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLDriverConnect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLDriverConnect"
c_SQLDriverConnect :: Ptr () -> CIntPtr -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> Word16 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- hwnd : INT_PTR -> CIntPtr
-- szConnStrIn : BYTE* -> Ptr Word8
-- cchConnStrIn : SHORT -> Int16
-- szConnStrOut : BYTE* optional, out -> Ptr Word8
-- cchConnStrOutMax : SHORT -> Int16
-- pcchConnStrOut : SHORT* optional, out -> Ptr Int16
-- fDriverCompletion : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqldriverconnect =
foreign "SQLDriverConnect"
((ptr void) @-> intptr_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> uint16_t @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* hwnd : INT_PTR -> intptr_t *)
(* 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) *)
(* fDriverCompletion : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLDriverConnect" sqldriver-connect :convention :stdcall) :int16
(hdbc :pointer) ; void* in/out
(hwnd :int64) ; INT_PTR
(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
(f-driver-completion :uint16)) ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLDriverConnect = Win32::API::More->new('ODBC32',
'short SQLDriverConnect(LPVOID hdbc, LPARAM hwnd, LPVOID szConnStrIn, short cchConnStrIn, LPVOID szConnStrOut, short cchConnStrOutMax, LPVOID pcchConnStrOut, WORD fDriverCompletion)');
# my $ret = $SQLDriverConnect->Call($hdbc, $hwnd, $szConnStrIn, $cchConnStrIn, $szConnStrOut, $cchConnStrOutMax, $pcchConnStrOut, $fDriverCompletion);
# hdbc : void* in/out -> LPVOID
# hwnd : INT_PTR -> LPARAM
# szConnStrIn : BYTE* -> LPVOID
# cchConnStrIn : SHORT -> short
# szConnStrOut : BYTE* optional, out -> LPVOID
# cchConnStrOutMax : SHORT -> short
# pcchConnStrOut : SHORT* optional, out -> LPVOID
# fDriverCompletion : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLDriverConnectA (ANSI版) — 接続文字列を用いてデータソースへ接続する。
- f SQLDriverConnectW (Unicode版) — 接続文字列やダイアログでデータソースに接続する(Unicode)。