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

SQLGetDescRec

関数
記述子レコードの複数フィールド値をまとめて取得する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLGetDescRec(
    void* DescriptorHandle,
    SHORT RecNumber,
    BYTE* Name,   // optional
    SHORT BufferLength,
    SHORT* StringLengthPtr,   // optional
    SHORT* TypePtr,   // optional
    SHORT* SubTypePtr,   // optional
    INT* LengthPtr,   // optional
    SHORT* PrecisionPtr,   // optional
    SHORT* ScalePtr,   // optional
    SHORT* NullablePtr   // optional
);

パラメーター

名前方向説明
DescriptorHandlevoid*inout対象の記述子ハンドル。
RecNumberSHORTin取得対象のレコード番号。1始まりで指定する。
NameBYTE*outoptional列名やパラメータ名を受け取るバッファ。ANSI文字列。
BufferLengthSHORTinNameバッファの文字数長。
StringLengthPtrSHORT*outoptional実際の名前の文字数を受け取るポインタ。NULL可。
TypePtrSHORT*outoptionalデータ型(SQL型)を受け取るポインタ。NULL可。
SubTypePtrSHORT*outoptional日時/区間型の場合のサブタイプを受け取るポインタ。NULL可。
LengthPtrINT*outoptional列の長さ(オクテット長)を受け取るポインタ。NULL可。
PrecisionPtrSHORT*outoptional数値の有効桁数(精度)を受け取るポインタ。NULL可。
ScalePtrSHORT*outoptional小数点以下桁数(スケール)を受け取るポインタ。NULL可。
NullablePtrSHORT*outoptionalNULL許容フラグを受け取るポインタ。SQL_NULLABLE等。NULL可。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLGetDescRec(
    void* DescriptorHandle,
    SHORT RecNumber,
    BYTE* Name,   // optional
    SHORT BufferLength,
    SHORT* StringLengthPtr,   // optional
    SHORT* TypePtr,   // optional
    SHORT* SubTypePtr,   // optional
    INT* LengthPtr,   // optional
    SHORT* PrecisionPtr,   // optional
    SHORT* ScalePtr,   // optional
    SHORT* NullablePtr   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLGetDescRec(
    IntPtr DescriptorHandle,   // void* in/out
    short RecNumber,   // SHORT
    IntPtr Name,   // BYTE* optional, out
    short BufferLength,   // SHORT
    IntPtr StringLengthPtr,   // SHORT* optional, out
    IntPtr TypePtr,   // SHORT* optional, out
    IntPtr SubTypePtr,   // SHORT* optional, out
    IntPtr LengthPtr,   // INT* optional, out
    IntPtr PrecisionPtr,   // SHORT* optional, out
    IntPtr ScalePtr,   // SHORT* optional, out
    IntPtr NullablePtr   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLGetDescRec(
    DescriptorHandle As IntPtr,   ' void* in/out
    RecNumber As Short,   ' SHORT
    Name As IntPtr,   ' BYTE* optional, out
    BufferLength As Short,   ' SHORT
    StringLengthPtr As IntPtr,   ' SHORT* optional, out
    TypePtr As IntPtr,   ' SHORT* optional, out
    SubTypePtr As IntPtr,   ' SHORT* optional, out
    LengthPtr As IntPtr,   ' INT* optional, out
    PrecisionPtr As IntPtr,   ' SHORT* optional, out
    ScalePtr As IntPtr,   ' SHORT* optional, out
    NullablePtr As IntPtr   ' SHORT* optional, out
) As Short
End Function
' DescriptorHandle : void* in/out
' RecNumber : SHORT
' Name : BYTE* optional, out
' BufferLength : SHORT
' StringLengthPtr : SHORT* optional, out
' TypePtr : SHORT* optional, out
' SubTypePtr : SHORT* optional, out
' LengthPtr : INT* optional, out
' PrecisionPtr : SHORT* optional, out
' ScalePtr : SHORT* optional, out
' NullablePtr : SHORT* optional, out
Declare PtrSafe Function SQLGetDescRec Lib "odbc32" ( _
    ByVal DescriptorHandle As LongPtr, _
    ByVal RecNumber As Integer, _
    ByVal Name As LongPtr, _
    ByVal BufferLength As Integer, _
    ByVal StringLengthPtr As LongPtr, _
    ByVal TypePtr As LongPtr, _
    ByVal SubTypePtr As LongPtr, _
    ByVal LengthPtr As LongPtr, _
    ByVal PrecisionPtr As LongPtr, _
    ByVal ScalePtr As LongPtr, _
    ByVal NullablePtr As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLGetDescRec = ctypes.windll.odbc32.SQLGetDescRec
SQLGetDescRec.restype = ctypes.c_short
SQLGetDescRec.argtypes = [
    ctypes.POINTER(None),  # DescriptorHandle : void* in/out
    ctypes.c_short,  # RecNumber : SHORT
    ctypes.POINTER(ctypes.c_ubyte),  # Name : BYTE* optional, out
    ctypes.c_short,  # BufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # StringLengthPtr : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # TypePtr : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # SubTypePtr : SHORT* optional, out
    ctypes.POINTER(ctypes.c_int),  # LengthPtr : INT* optional, out
    ctypes.POINTER(ctypes.c_short),  # PrecisionPtr : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # ScalePtr : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # NullablePtr : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDescRec = Fiddle::Function.new(
  lib['SQLGetDescRec'],
  [
    Fiddle::TYPE_VOIDP,  # DescriptorHandle : void* in/out
    Fiddle::TYPE_SHORT,  # RecNumber : SHORT
    Fiddle::TYPE_VOIDP,  # Name : BYTE* optional, out
    Fiddle::TYPE_SHORT,  # BufferLength : SHORT
    Fiddle::TYPE_VOIDP,  # StringLengthPtr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # TypePtr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # SubTypePtr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # LengthPtr : INT* optional, out
    Fiddle::TYPE_VOIDP,  # PrecisionPtr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # ScalePtr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # NullablePtr : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetDescRec(
        DescriptorHandle: *mut (),  // void* in/out
        RecNumber: i16,  // SHORT
        Name: *mut u8,  // BYTE* optional, out
        BufferLength: i16,  // SHORT
        StringLengthPtr: *mut i16,  // SHORT* optional, out
        TypePtr: *mut i16,  // SHORT* optional, out
        SubTypePtr: *mut i16,  // SHORT* optional, out
        LengthPtr: *mut i32,  // INT* optional, out
        PrecisionPtr: *mut i16,  // SHORT* optional, out
        ScalePtr: *mut i16,  // SHORT* optional, out
        NullablePtr: *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 SQLGetDescRec(IntPtr DescriptorHandle, short RecNumber, IntPtr Name, short BufferLength, IntPtr StringLengthPtr, IntPtr TypePtr, IntPtr SubTypePtr, IntPtr LengthPtr, IntPtr PrecisionPtr, IntPtr ScalePtr, IntPtr NullablePtr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDescRec' -Namespace Win32 -PassThru
# $api::SQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr, NullablePtr)
#uselib "ODBC32.dll"
#func global SQLGetDescRec "SQLGetDescRec" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLGetDescRec DescriptorHandle, RecNumber, varptr(Name), BufferLength, varptr(StringLengthPtr), varptr(TypePtr), varptr(SubTypePtr), varptr(LengthPtr), varptr(PrecisionPtr), varptr(ScalePtr), varptr(NullablePtr)   ; 戻り値は stat
; DescriptorHandle : void* in/out -> "sptr"
; RecNumber : SHORT -> "sptr"
; Name : BYTE* optional, out -> "sptr"
; BufferLength : SHORT -> "sptr"
; StringLengthPtr : SHORT* optional, out -> "sptr"
; TypePtr : SHORT* optional, out -> "sptr"
; SubTypePtr : SHORT* optional, out -> "sptr"
; LengthPtr : INT* optional, out -> "sptr"
; PrecisionPtr : SHORT* optional, out -> "sptr"
; ScalePtr : SHORT* optional, out -> "sptr"
; NullablePtr : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetDescRec "SQLGetDescRec" sptr, int, var, int, var, var, var, var, var, var, var
; res = SQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr, NullablePtr)
; DescriptorHandle : void* in/out -> "sptr"
; RecNumber : SHORT -> "int"
; Name : BYTE* optional, out -> "var"
; BufferLength : SHORT -> "int"
; StringLengthPtr : SHORT* optional, out -> "var"
; TypePtr : SHORT* optional, out -> "var"
; SubTypePtr : SHORT* optional, out -> "var"
; LengthPtr : INT* optional, out -> "var"
; PrecisionPtr : SHORT* optional, out -> "var"
; ScalePtr : SHORT* optional, out -> "var"
; NullablePtr : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetDescRec(void* DescriptorHandle, SHORT RecNumber, BYTE* Name, SHORT BufferLength, SHORT* StringLengthPtr, SHORT* TypePtr, SHORT* SubTypePtr, INT* LengthPtr, SHORT* PrecisionPtr, SHORT* ScalePtr, SHORT* NullablePtr)
#uselib "ODBC32.dll"
#cfunc global SQLGetDescRec "SQLGetDescRec" intptr, int, var, int, var, var, var, var, var, var, var
; res = SQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr, NullablePtr)
; DescriptorHandle : void* in/out -> "intptr"
; RecNumber : SHORT -> "int"
; Name : BYTE* optional, out -> "var"
; BufferLength : SHORT -> "int"
; StringLengthPtr : SHORT* optional, out -> "var"
; TypePtr : SHORT* optional, out -> "var"
; SubTypePtr : SHORT* optional, out -> "var"
; LengthPtr : INT* optional, out -> "var"
; PrecisionPtr : SHORT* optional, out -> "var"
; ScalePtr : SHORT* optional, out -> "var"
; NullablePtr : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDescRec = odbc32.NewProc("SQLGetDescRec")
)

// DescriptorHandle (void* in/out), RecNumber (SHORT), Name (BYTE* optional, out), BufferLength (SHORT), StringLengthPtr (SHORT* optional, out), TypePtr (SHORT* optional, out), SubTypePtr (SHORT* optional, out), LengthPtr (INT* optional, out), PrecisionPtr (SHORT* optional, out), ScalePtr (SHORT* optional, out), NullablePtr (SHORT* optional, out)
r1, _, err := procSQLGetDescRec.Call(
	uintptr(DescriptorHandle),
	uintptr(RecNumber),
	uintptr(Name),
	uintptr(BufferLength),
	uintptr(StringLengthPtr),
	uintptr(TypePtr),
	uintptr(SubTypePtr),
	uintptr(LengthPtr),
	uintptr(PrecisionPtr),
	uintptr(ScalePtr),
	uintptr(NullablePtr),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLGetDescRec(
  DescriptorHandle: Pointer;   // void* in/out
  RecNumber: Smallint;   // SHORT
  Name: Pointer;   // BYTE* optional, out
  BufferLength: Smallint;   // SHORT
  StringLengthPtr: Pointer;   // SHORT* optional, out
  TypePtr: Pointer;   // SHORT* optional, out
  SubTypePtr: Pointer;   // SHORT* optional, out
  LengthPtr: Pointer;   // INT* optional, out
  PrecisionPtr: Pointer;   // SHORT* optional, out
  ScalePtr: Pointer;   // SHORT* optional, out
  NullablePtr: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDescRec';
result := DllCall("ODBC32\SQLGetDescRec"
    , "Ptr", DescriptorHandle   ; void* in/out
    , "Short", RecNumber   ; SHORT
    , "Ptr", Name   ; BYTE* optional, out
    , "Short", BufferLength   ; SHORT
    , "Ptr", StringLengthPtr   ; SHORT* optional, out
    , "Ptr", TypePtr   ; SHORT* optional, out
    , "Ptr", SubTypePtr   ; SHORT* optional, out
    , "Ptr", LengthPtr   ; INT* optional, out
    , "Ptr", PrecisionPtr   ; SHORT* optional, out
    , "Ptr", ScalePtr   ; SHORT* optional, out
    , "Ptr", NullablePtr   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr, NullablePtr) = DLL("ODBC32.dll", "int SQLGetDescRec(void*, int, void*, int, void*, void*, void*, void*, void*, void*, void*)")
# 呼び出し: SQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr, NullablePtr)
# DescriptorHandle : void* in/out -> "void*"
# RecNumber : SHORT -> "int"
# Name : BYTE* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# StringLengthPtr : SHORT* optional, out -> "void*"
# TypePtr : SHORT* optional, out -> "void*"
# SubTypePtr : SHORT* optional, out -> "void*"
# LengthPtr : INT* optional, out -> "void*"
# PrecisionPtr : SHORT* optional, out -> "void*"
# ScalePtr : SHORT* optional, out -> "void*"
# NullablePtr : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

foreign import stdcall safe "SQLGetDescRec"
  c_SQLGetDescRec :: Ptr () -> Int16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Int32 -> Ptr Int16 -> Ptr Int16 -> Ptr Int16 -> IO Int16
-- DescriptorHandle : void* in/out -> Ptr ()
-- RecNumber : SHORT -> Int16
-- Name : BYTE* optional, out -> Ptr Word8
-- BufferLength : SHORT -> Int16
-- StringLengthPtr : SHORT* optional, out -> Ptr Int16
-- TypePtr : SHORT* optional, out -> Ptr Int16
-- SubTypePtr : SHORT* optional, out -> Ptr Int16
-- LengthPtr : INT* optional, out -> Ptr Int32
-- PrecisionPtr : SHORT* optional, out -> Ptr Int16
-- ScalePtr : SHORT* optional, out -> Ptr Int16
-- NullablePtr : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlgetdescrec =
  foreign "SQLGetDescRec"
    ((ptr void) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int32_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> returning int16_t)
(* DescriptorHandle : void* in/out -> (ptr void) *)
(* RecNumber : SHORT -> int16_t *)
(* Name : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferLength : SHORT -> int16_t *)
(* StringLengthPtr : SHORT* optional, out -> (ptr int16_t) *)
(* TypePtr : SHORT* optional, out -> (ptr int16_t) *)
(* SubTypePtr : SHORT* optional, out -> (ptr int16_t) *)
(* LengthPtr : INT* optional, out -> (ptr int32_t) *)
(* PrecisionPtr : SHORT* optional, out -> (ptr int16_t) *)
(* ScalePtr : SHORT* optional, out -> (ptr int16_t) *)
(* NullablePtr : 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 ("SQLGetDescRec" sqlget-desc-rec :convention :stdcall) :int16
  (descriptor-handle :pointer)   ; void* in/out
  (rec-number :int16)   ; SHORT
  (name :pointer)   ; BYTE* optional, out
  (buffer-length :int16)   ; SHORT
  (string-length-ptr :pointer)   ; SHORT* optional, out
  (type-ptr :pointer)   ; SHORT* optional, out
  (sub-type-ptr :pointer)   ; SHORT* optional, out
  (length-ptr :pointer)   ; INT* optional, out
  (precision-ptr :pointer)   ; SHORT* optional, out
  (scale-ptr :pointer)   ; SHORT* optional, out
  (nullable-ptr :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLGetDescRec = Win32::API::More->new('ODBC32',
    'short SQLGetDescRec(LPVOID DescriptorHandle, short RecNumber, LPVOID Name, short BufferLength, LPVOID StringLengthPtr, LPVOID TypePtr, LPVOID SubTypePtr, LPVOID LengthPtr, LPVOID PrecisionPtr, LPVOID ScalePtr, LPVOID NullablePtr)');
# my $ret = $SQLGetDescRec->Call($DescriptorHandle, $RecNumber, $Name, $BufferLength, $StringLengthPtr, $TypePtr, $SubTypePtr, $LengthPtr, $PrecisionPtr, $ScalePtr, $NullablePtr);
# DescriptorHandle : void* in/out -> LPVOID
# RecNumber : SHORT -> short
# Name : BYTE* optional, out -> LPVOID
# BufferLength : SHORT -> short
# StringLengthPtr : SHORT* optional, out -> LPVOID
# TypePtr : SHORT* optional, out -> LPVOID
# SubTypePtr : SHORT* optional, out -> LPVOID
# LengthPtr : INT* optional, out -> LPVOID
# PrecisionPtr : SHORT* optional, out -> LPVOID
# ScalePtr : SHORT* optional, out -> LPVOID
# NullablePtr : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い