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