ホーム › System.Search › SQLConnectA
SQLConnectA
関数DSN名とユーザー認証でデータソースに接続する(ANSI)。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLConnectA(
void* hdbc,
BYTE* szDSN,
SHORT cbDSN,
BYTE* szUID,
SHORT cbUID,
BYTE* szAuthStr,
SHORT cbAuthStr
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdbc | void* | inout |
| szDSN | BYTE* | in |
| cbDSN | SHORT | in |
| szUID | BYTE* | in |
| cbUID | SHORT | in |
| szAuthStr | BYTE* | in |
| cbAuthStr | SHORT | in |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLConnectA(
void* hdbc,
BYTE* szDSN,
SHORT cbDSN,
BYTE* szUID,
SHORT cbUID,
BYTE* szAuthStr,
SHORT cbAuthStr
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLConnectA(
IntPtr hdbc, // void* in/out
IntPtr szDSN, // BYTE*
short cbDSN, // SHORT
IntPtr szUID, // BYTE*
short cbUID, // SHORT
IntPtr szAuthStr, // BYTE*
short cbAuthStr // SHORT
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLConnectA(
hdbc As IntPtr, ' void* in/out
szDSN As IntPtr, ' BYTE*
cbDSN As Short, ' SHORT
szUID As IntPtr, ' BYTE*
cbUID As Short, ' SHORT
szAuthStr As IntPtr, ' BYTE*
cbAuthStr As Short ' SHORT
) As Short
End Function' hdbc : void* in/out
' szDSN : BYTE*
' cbDSN : SHORT
' szUID : BYTE*
' cbUID : SHORT
' szAuthStr : BYTE*
' cbAuthStr : SHORT
Declare PtrSafe Function SQLConnectA Lib "odbc32" ( _
ByVal hdbc As LongPtr, _
ByVal szDSN As LongPtr, _
ByVal cbDSN As Integer, _
ByVal szUID As LongPtr, _
ByVal cbUID As Integer, _
ByVal szAuthStr As LongPtr, _
ByVal cbAuthStr As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLConnectA = ctypes.windll.odbc32.SQLConnectA
SQLConnectA.restype = ctypes.c_short
SQLConnectA.argtypes = [
ctypes.POINTER(None), # hdbc : void* in/out
ctypes.POINTER(ctypes.c_ubyte), # szDSN : BYTE*
ctypes.c_short, # cbDSN : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szUID : BYTE*
ctypes.c_short, # cbUID : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szAuthStr : BYTE*
ctypes.c_short, # cbAuthStr : SHORT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLConnectA = Fiddle::Function.new(
lib['SQLConnectA'],
[
Fiddle::TYPE_VOIDP, # hdbc : void* in/out
Fiddle::TYPE_VOIDP, # szDSN : BYTE*
Fiddle::TYPE_SHORT, # cbDSN : SHORT
Fiddle::TYPE_VOIDP, # szUID : BYTE*
Fiddle::TYPE_SHORT, # cbUID : SHORT
Fiddle::TYPE_VOIDP, # szAuthStr : BYTE*
Fiddle::TYPE_SHORT, # cbAuthStr : SHORT
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLConnectA(
hdbc: *mut (), // void* in/out
szDSN: *mut u8, // BYTE*
cbDSN: i16, // SHORT
szUID: *mut u8, // BYTE*
cbUID: i16, // SHORT
szAuthStr: *mut u8, // BYTE*
cbAuthStr: i16 // SHORT
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLConnectA(IntPtr hdbc, IntPtr szDSN, short cbDSN, IntPtr szUID, short cbUID, IntPtr szAuthStr, short cbAuthStr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLConnectA' -Namespace Win32 -PassThru
# $api::SQLConnectA(hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr)#uselib "ODBC32.dll"
#func global SQLConnectA "SQLConnectA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLConnectA hdbc, varptr(szDSN), cbDSN, varptr(szUID), cbUID, varptr(szAuthStr), cbAuthStr ; 戻り値は stat
; hdbc : void* in/out -> "sptr"
; szDSN : BYTE* -> "sptr"
; cbDSN : SHORT -> "sptr"
; szUID : BYTE* -> "sptr"
; cbUID : SHORT -> "sptr"
; szAuthStr : BYTE* -> "sptr"
; cbAuthStr : SHORT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLConnectA "SQLConnectA" sptr, var, int, var, int, var, int ; res = SQLConnectA(hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr) ; hdbc : void* in/out -> "sptr" ; szDSN : BYTE* -> "var" ; cbDSN : SHORT -> "int" ; szUID : BYTE* -> "var" ; cbUID : SHORT -> "int" ; szAuthStr : BYTE* -> "var" ; cbAuthStr : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLConnectA "SQLConnectA" sptr, sptr, int, sptr, int, sptr, int ; res = SQLConnectA(hdbc, varptr(szDSN), cbDSN, varptr(szUID), cbUID, varptr(szAuthStr), cbAuthStr) ; hdbc : void* in/out -> "sptr" ; szDSN : BYTE* -> "sptr" ; cbDSN : SHORT -> "int" ; szUID : BYTE* -> "sptr" ; cbUID : SHORT -> "int" ; szAuthStr : BYTE* -> "sptr" ; cbAuthStr : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLConnectA(void* hdbc, BYTE* szDSN, SHORT cbDSN, BYTE* szUID, SHORT cbUID, BYTE* szAuthStr, SHORT cbAuthStr) #uselib "ODBC32.dll" #cfunc global SQLConnectA "SQLConnectA" intptr, var, int, var, int, var, int ; res = SQLConnectA(hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr) ; hdbc : void* in/out -> "intptr" ; szDSN : BYTE* -> "var" ; cbDSN : SHORT -> "int" ; szUID : BYTE* -> "var" ; cbUID : SHORT -> "int" ; szAuthStr : BYTE* -> "var" ; cbAuthStr : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLConnectA(void* hdbc, BYTE* szDSN, SHORT cbDSN, BYTE* szUID, SHORT cbUID, BYTE* szAuthStr, SHORT cbAuthStr) #uselib "ODBC32.dll" #cfunc global SQLConnectA "SQLConnectA" intptr, intptr, int, intptr, int, intptr, int ; res = SQLConnectA(hdbc, varptr(szDSN), cbDSN, varptr(szUID), cbUID, varptr(szAuthStr), cbAuthStr) ; hdbc : void* in/out -> "intptr" ; szDSN : BYTE* -> "intptr" ; cbDSN : SHORT -> "int" ; szUID : BYTE* -> "intptr" ; cbUID : SHORT -> "int" ; szAuthStr : BYTE* -> "intptr" ; cbAuthStr : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLConnectA = odbc32.NewProc("SQLConnectA")
)
// hdbc (void* in/out), szDSN (BYTE*), cbDSN (SHORT), szUID (BYTE*), cbUID (SHORT), szAuthStr (BYTE*), cbAuthStr (SHORT)
r1, _, err := procSQLConnectA.Call(
uintptr(hdbc),
uintptr(szDSN),
uintptr(cbDSN),
uintptr(szUID),
uintptr(cbUID),
uintptr(szAuthStr),
uintptr(cbAuthStr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLConnectA(
hdbc: Pointer; // void* in/out
szDSN: Pointer; // BYTE*
cbDSN: Smallint; // SHORT
szUID: Pointer; // BYTE*
cbUID: Smallint; // SHORT
szAuthStr: Pointer; // BYTE*
cbAuthStr: Smallint // SHORT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLConnectA';result := DllCall("ODBC32\SQLConnectA"
, "Ptr", hdbc ; void* in/out
, "Ptr", szDSN ; BYTE*
, "Short", cbDSN ; SHORT
, "Ptr", szUID ; BYTE*
, "Short", cbUID ; SHORT
, "Ptr", szAuthStr ; BYTE*
, "Short", cbAuthStr ; SHORT
, "Short") ; return: SHORT●SQLConnectA(hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr) = DLL("ODBC32.dll", "int SQLConnectA(void*, void*, int, void*, int, void*, int)")
# 呼び出し: SQLConnectA(hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr)
# hdbc : void* in/out -> "void*"
# szDSN : BYTE* -> "void*"
# cbDSN : SHORT -> "int"
# szUID : BYTE* -> "void*"
# cbUID : SHORT -> "int"
# szAuthStr : BYTE* -> "void*"
# cbAuthStr : SHORT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。