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

SQLDataSources

関数
利用可能なODBCデータソースを順に列挙する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// 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
);

パラメーター

名前方向説明
EnvironmentHandlevoid*inout列挙に使用する環境ハンドル(HENV)。
DirectionWORDin列挙の方向/開始位置(SQL_FETCH_FIRST/NEXT等)。
ServerNameBYTE*outoptionalデータソース名を受け取るバッファへのポインタ。
BufferLength1SHORTinServerNameバッファのバイト長。
NameLength1PtrSHORT*outoptionalデータソース名の実際の長さを受け取るポインタ。
DescriptionBYTE*outoptionalドライバの説明を受け取るバッファへのポインタ。
BufferLength2SHORTinDescriptionバッファのバイト長。
NameLength2PtrSHORT*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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // SHORT
function 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)。
const std = @import("std");

extern "odbc32" fn SQLDataSources(
    EnvironmentHandle: ?*anyopaque, // void* in/out
    Direction: u16, // WORD
    ServerName: [*c]u8, // BYTE* optional, out
    BufferLength1: i16, // SHORT
    NameLength1Ptr: [*c]i16, // SHORT* optional, out
    Description: [*c]u8, // BYTE* optional, out
    BufferLength2: i16, // SHORT
    NameLength2Ptr: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
proc SQLDataSources(
    EnvironmentHandle: pointer,  # void* in/out
    Direction: uint16,  # WORD
    ServerName: ptr uint8,  # BYTE* optional, out
    BufferLength1: int16,  # SHORT
    NameLength1Ptr: ptr int16,  # SHORT* optional, out
    Description: ptr uint8,  # BYTE* optional, out
    BufferLength2: int16,  # SHORT
    NameLength2Ptr: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLDataSources", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLDataSources(
    void* EnvironmentHandle,   // void* in/out
    ushort Direction,   // WORD
    ubyte* ServerName,   // BYTE* optional, out
    short BufferLength1,   // SHORT
    short* NameLength1Ptr,   // SHORT* optional, out
    ubyte* Description,   // BYTE* optional, out
    short BufferLength2,   // SHORT
    short* NameLength2Ptr   // SHORT* optional, out
);
ccall((:SQLDataSources, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, UInt16, Ptr{UInt8}, Int16, Ptr{Int16}, Ptr{UInt8}, Int16, Ptr{Int16}),
      EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1Ptr, Description, BufferLength2, NameLength2Ptr)
# EnvironmentHandle : void* in/out -> Ptr{Cvoid}
# Direction : WORD -> UInt16
# ServerName : BYTE* optional, out -> Ptr{UInt8}
# BufferLength1 : SHORT -> Int16
# NameLength1Ptr : SHORT* optional, out -> Ptr{Int16}
# Description : BYTE* optional, out -> Ptr{UInt8}
# BufferLength2 : SHORT -> Int16
# NameLength2Ptr : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLDataSources(
    void* EnvironmentHandle,
    uint16_t Direction,
    uint8_t* ServerName,
    int16_t BufferLength1,
    int16_t* NameLength1Ptr,
    uint8_t* Description,
    int16_t BufferLength2,
    int16_t* NameLength2Ptr);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLDataSources(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1Ptr, Description, BufferLength2, NameLength2Ptr)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLDataSources = lib.func('__stdcall', 'SQLDataSources', 'int16_t', ['void *', 'uint16_t', 'uint8_t *', 'int16_t', 'int16_t *', 'uint8_t *', 'int16_t', 'int16_t *']);
// SQLDataSources(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1Ptr, Description, BufferLength2, NameLength2Ptr)
// EnvironmentHandle : void* in/out -> 'void *'
// Direction : WORD -> 'uint16_t'
// ServerName : BYTE* optional, out -> 'uint8_t *'
// BufferLength1 : SHORT -> 'int16_t'
// NameLength1Ptr : SHORT* optional, out -> 'int16_t *'
// Description : BYTE* optional, out -> 'uint8_t *'
// BufferLength2 : SHORT -> 'int16_t'
// NameLength2Ptr : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLDataSources: { parameters: ["pointer", "u16", "pointer", "i16", "pointer", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLDataSources(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1Ptr, Description, BufferLength2, NameLength2Ptr)
// EnvironmentHandle : void* in/out -> "pointer"
// Direction : WORD -> "u16"
// ServerName : BYTE* optional, out -> "pointer"
// BufferLength1 : SHORT -> "i16"
// NameLength1Ptr : SHORT* optional, out -> "pointer"
// Description : BYTE* optional, out -> "pointer"
// BufferLength2 : SHORT -> "i16"
// NameLength2Ptr : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLDataSources(
    void* EnvironmentHandle,
    uint16_t Direction,
    uint8_t* ServerName,
    int16_t BufferLength1,
    int16_t* NameLength1Ptr,
    uint8_t* Description,
    int16_t BufferLength2,
    int16_t* NameLength2Ptr);
C, "ODBC32.dll");
// $ffi->SQLDataSources(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1Ptr, Description, BufferLength2, NameLength2Ptr);
// 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
// 構造体/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 SQLDataSources(
        Pointer EnvironmentHandle,   // void* in/out
        short Direction,   // WORD
        byte[] ServerName,   // BYTE* optional, out
        short BufferLength1,   // SHORT
        ShortByReference NameLength1Ptr,   // SHORT* optional, out
        byte[] Description,   // BYTE* optional, out
        short BufferLength2,   // SHORT
        ShortByReference NameLength2Ptr   // SHORT* optional, out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLDataSources = SQLDataSources(
    EnvironmentHandle : Void*,   # void* in/out
    Direction : UInt16,   # WORD
    ServerName : UInt8*,   # BYTE* optional, out
    BufferLength1 : Int16,   # SHORT
    NameLength1Ptr : Int16*,   # SHORT* optional, out
    Description : UInt8*,   # BYTE* optional, out
    BufferLength2 : Int16,   # SHORT
    NameLength2Ptr : 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 SQLDataSourcesNative = Int16 Function(Pointer<Void>, Uint16, Pointer<Uint8>, Int16, Pointer<Int16>, Pointer<Uint8>, Int16, Pointer<Int16>);
typedef SQLDataSourcesDart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, Pointer<Int16>, Pointer<Uint8>, int, Pointer<Int16>);
final SQLDataSources = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLDataSourcesNative, SQLDataSourcesDart>('SQLDataSources');
// EnvironmentHandle : void* in/out -> Pointer<Void>
// Direction : WORD -> Uint16
// ServerName : BYTE* optional, out -> Pointer<Uint8>
// BufferLength1 : SHORT -> Int16
// NameLength1Ptr : SHORT* optional, out -> Pointer<Int16>
// Description : BYTE* optional, out -> Pointer<Uint8>
// BufferLength2 : SHORT -> Int16
// NameLength2Ptr : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLDataSources"
  c_SQLDataSources :: Ptr () -> Word16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- EnvironmentHandle : void* in/out -> Ptr ()
-- Direction : WORD -> Word16
-- ServerName : BYTE* optional, out -> Ptr Word8
-- BufferLength1 : SHORT -> Int16
-- NameLength1Ptr : SHORT* optional, out -> Ptr Int16
-- Description : BYTE* optional, out -> Ptr Word8
-- BufferLength2 : SHORT -> Int16
-- NameLength2Ptr : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqldatasources =
  foreign "SQLDataSources"
    ((ptr void) @-> uint16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* EnvironmentHandle : void* in/out -> (ptr void) *)
(* Direction : WORD -> uint16_t *)
(* ServerName : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferLength1 : SHORT -> int16_t *)
(* NameLength1Ptr : SHORT* optional, out -> (ptr int16_t) *)
(* Description : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferLength2 : SHORT -> int16_t *)
(* NameLength2Ptr : 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 ("SQLDataSources" sqldata-sources :convention :stdcall) :int16
  (environment-handle :pointer)   ; void* in/out
  (direction :uint16)   ; WORD
  (server-name :pointer)   ; BYTE* optional, out
  (buffer-length1 :int16)   ; SHORT
  (name-length1-ptr :pointer)   ; SHORT* optional, out
  (description :pointer)   ; BYTE* optional, out
  (buffer-length2 :int16)   ; SHORT
  (name-length2-ptr :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLDataSources = Win32::API::More->new('ODBC32',
    'short SQLDataSources(LPVOID EnvironmentHandle, WORD Direction, LPVOID ServerName, short BufferLength1, LPVOID NameLength1Ptr, LPVOID Description, short BufferLength2, LPVOID NameLength2Ptr)');
# my $ret = $SQLDataSources->Call($EnvironmentHandle, $Direction, $ServerName, $BufferLength1, $NameLength1Ptr, $Description, $BufferLength2, $NameLength2Ptr);
# EnvironmentHandle : void* in/out -> LPVOID
# Direction : WORD -> WORD
# ServerName : BYTE* optional, out -> LPVOID
# BufferLength1 : SHORT -> short
# NameLength1Ptr : SHORT* optional, out -> LPVOID
# Description : BYTE* optional, out -> LPVOID
# BufferLength2 : SHORT -> short
# NameLength2Ptr : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い