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

SQLConnectW

関数
DSN名とユーザー認証でデータソースに接続する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

SHORT SQLConnectW(
    void* hdbc,
    WORD* szDSN,
    SHORT cchDSN,
    WORD* szUID,
    SHORT cchUID,
    WORD* szAuthStr,
    SHORT cchAuthStr
);

パラメーター

名前方向
hdbcvoid*inout
szDSNWORD*in
cchDSNSHORTin
szUIDWORD*in
cchUIDSHORTin
szAuthStrWORD*in
cchAuthStrSHORTin

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLConnectW = ctypes.windll.odbc32.SQLConnectW
SQLConnectW.restype = ctypes.c_short
SQLConnectW.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szDSN : WORD*
    ctypes.c_short,  # cchDSN : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szUID : WORD*
    ctypes.c_short,  # cchUID : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szAuthStr : WORD*
    ctypes.c_short,  # cchAuthStr : SHORT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLConnectW = odbc32.NewProc("SQLConnectW")
)

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