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

SQLDescribeCol

関数
結果セット列の名前や型などの属性を取得する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLDescribeCol(
    void* StatementHandle,
    WORD ColumnNumber,
    BYTE* ColumnName,   // optional
    SHORT BufferLength,
    SHORT* NameLength,   // optional
    SHORT* DataType,   // optional
    DWORD* ColumnSize,   // optional
    SHORT* DecimalDigits,   // optional
    SHORT* Nullable   // optional
);

パラメーター

名前方向説明
StatementHandlevoid*inout対象のステートメントハンドル(HSTMT)。
ColumnNumberWORDin記述を取得する結果列の番号。1始まり。
ColumnNameBYTE*outoptional列名を受け取るバッファへのポインタ。
BufferLengthSHORTinColumnNameバッファのバイト長。
NameLengthSHORT*outoptional列名の実際の長さを受け取るポインタ。
DataTypeSHORT*outoptional列のSQLデータ型を受け取るポインタ。
ColumnSizeDWORD*outoptional列のサイズ(精度)を受け取るポインタ。
DecimalDigitsSHORT*outoptional列の小数点以下桁数を受け取るポインタ。
NullableSHORT*outoptional列がNULL可かを受け取るポインタ(SQL_NULLABLE等)。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLDescribeCol(
    void* StatementHandle,
    WORD ColumnNumber,
    BYTE* ColumnName,   // optional
    SHORT BufferLength,
    SHORT* NameLength,   // optional
    SHORT* DataType,   // optional
    DWORD* ColumnSize,   // optional
    SHORT* DecimalDigits,   // optional
    SHORT* Nullable   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLDescribeCol(
    IntPtr StatementHandle,   // void* in/out
    ushort ColumnNumber,   // WORD
    IntPtr ColumnName,   // BYTE* optional, out
    short BufferLength,   // SHORT
    IntPtr NameLength,   // SHORT* optional, out
    IntPtr DataType,   // SHORT* optional, out
    IntPtr ColumnSize,   // DWORD* optional, out
    IntPtr DecimalDigits,   // SHORT* optional, out
    IntPtr Nullable   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLDescribeCol(
    StatementHandle As IntPtr,   ' void* in/out
    ColumnNumber As UShort,   ' WORD
    ColumnName As IntPtr,   ' BYTE* optional, out
    BufferLength As Short,   ' SHORT
    NameLength As IntPtr,   ' SHORT* optional, out
    DataType As IntPtr,   ' SHORT* optional, out
    ColumnSize As IntPtr,   ' DWORD* optional, out
    DecimalDigits As IntPtr,   ' SHORT* optional, out
    Nullable As IntPtr   ' SHORT* optional, out
) As Short
End Function
' StatementHandle : void* in/out
' ColumnNumber : WORD
' ColumnName : BYTE* optional, out
' BufferLength : SHORT
' NameLength : SHORT* optional, out
' DataType : SHORT* optional, out
' ColumnSize : DWORD* optional, out
' DecimalDigits : SHORT* optional, out
' Nullable : SHORT* optional, out
Declare PtrSafe Function SQLDescribeCol Lib "odbc32" ( _
    ByVal StatementHandle As LongPtr, _
    ByVal ColumnNumber As Integer, _
    ByVal ColumnName As LongPtr, _
    ByVal BufferLength As Integer, _
    ByVal NameLength As LongPtr, _
    ByVal DataType As LongPtr, _
    ByVal ColumnSize As LongPtr, _
    ByVal DecimalDigits As LongPtr, _
    ByVal Nullable As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLDescribeCol = ctypes.windll.odbc32.SQLDescribeCol
SQLDescribeCol.restype = ctypes.c_short
SQLDescribeCol.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.c_ushort,  # ColumnNumber : WORD
    ctypes.POINTER(ctypes.c_ubyte),  # ColumnName : BYTE* optional, out
    ctypes.c_short,  # BufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # NameLength : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # DataType : SHORT* optional, out
    ctypes.POINTER(wintypes.DWORD),  # ColumnSize : DWORD* optional, out
    ctypes.POINTER(ctypes.c_short),  # DecimalDigits : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # Nullable : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLDescribeCol = odbc32.NewProc("SQLDescribeCol")
)

// StatementHandle (void* in/out), ColumnNumber (WORD), ColumnName (BYTE* optional, out), BufferLength (SHORT), NameLength (SHORT* optional, out), DataType (SHORT* optional, out), ColumnSize (DWORD* optional, out), DecimalDigits (SHORT* optional, out), Nullable (SHORT* optional, out)
r1, _, err := procSQLDescribeCol.Call(
	uintptr(StatementHandle),
	uintptr(ColumnNumber),
	uintptr(ColumnName),
	uintptr(BufferLength),
	uintptr(NameLength),
	uintptr(DataType),
	uintptr(ColumnSize),
	uintptr(DecimalDigits),
	uintptr(Nullable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLDescribeCol(
  StatementHandle: Pointer;   // void* in/out
  ColumnNumber: Word;   // WORD
  ColumnName: Pointer;   // BYTE* optional, out
  BufferLength: Smallint;   // SHORT
  NameLength: Pointer;   // SHORT* optional, out
  DataType: Pointer;   // SHORT* optional, out
  ColumnSize: Pointer;   // DWORD* optional, out
  DecimalDigits: Pointer;   // SHORT* optional, out
  Nullable: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLDescribeCol';
result := DllCall("ODBC32\SQLDescribeCol"
    , "Ptr", StatementHandle   ; void* in/out
    , "UShort", ColumnNumber   ; WORD
    , "Ptr", ColumnName   ; BYTE* optional, out
    , "Short", BufferLength   ; SHORT
    , "Ptr", NameLength   ; SHORT* optional, out
    , "Ptr", DataType   ; SHORT* optional, out
    , "Ptr", ColumnSize   ; DWORD* optional, out
    , "Ptr", DecimalDigits   ; SHORT* optional, out
    , "Ptr", Nullable   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLDescribeCol(StatementHandle, ColumnNumber, ColumnName, BufferLength, NameLength, DataType, ColumnSize, DecimalDigits, Nullable) = DLL("ODBC32.dll", "int SQLDescribeCol(void*, int, void*, int, void*, void*, void*, void*, void*)")
# 呼び出し: SQLDescribeCol(StatementHandle, ColumnNumber, ColumnName, BufferLength, NameLength, DataType, ColumnSize, DecimalDigits, Nullable)
# StatementHandle : void* in/out -> "void*"
# ColumnNumber : WORD -> "int"
# ColumnName : BYTE* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# NameLength : SHORT* optional, out -> "void*"
# DataType : SHORT* optional, out -> "void*"
# ColumnSize : DWORD* optional, out -> "void*"
# DecimalDigits : SHORT* optional, out -> "void*"
# Nullable : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

foreign import stdcall safe "SQLDescribeCol"
  c_SQLDescribeCol :: Ptr () -> Word16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Word32 -> Ptr Int16 -> Ptr Int16 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- ColumnNumber : WORD -> Word16
-- ColumnName : BYTE* optional, out -> Ptr Word8
-- BufferLength : SHORT -> Int16
-- NameLength : SHORT* optional, out -> Ptr Int16
-- DataType : SHORT* optional, out -> Ptr Int16
-- ColumnSize : DWORD* optional, out -> Ptr Word32
-- DecimalDigits : SHORT* optional, out -> Ptr Int16
-- Nullable : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqldescribecol =
  foreign "SQLDescribeCol"
    ((ptr void) @-> uint16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr uint32_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* ColumnNumber : WORD -> uint16_t *)
(* ColumnName : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferLength : SHORT -> int16_t *)
(* NameLength : SHORT* optional, out -> (ptr int16_t) *)
(* DataType : SHORT* optional, out -> (ptr int16_t) *)
(* ColumnSize : DWORD* optional, out -> (ptr uint32_t) *)
(* DecimalDigits : SHORT* optional, out -> (ptr int16_t) *)
(* Nullable : 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 ("SQLDescribeCol" sqldescribe-col :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (column-number :uint16)   ; WORD
  (column-name :pointer)   ; BYTE* optional, out
  (buffer-length :int16)   ; SHORT
  (name-length :pointer)   ; SHORT* optional, out
  (data-type :pointer)   ; SHORT* optional, out
  (column-size :pointer)   ; DWORD* optional, out
  (decimal-digits :pointer)   ; SHORT* optional, out
  (nullable :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLDescribeCol = Win32::API::More->new('ODBC32',
    'short SQLDescribeCol(LPVOID StatementHandle, WORD ColumnNumber, LPVOID ColumnName, short BufferLength, LPVOID NameLength, LPVOID DataType, LPVOID ColumnSize, LPVOID DecimalDigits, LPVOID Nullable)');
# my $ret = $SQLDescribeCol->Call($StatementHandle, $ColumnNumber, $ColumnName, $BufferLength, $NameLength, $DataType, $ColumnSize, $DecimalDigits, $Nullable);
# StatementHandle : void* in/out -> LPVOID
# ColumnNumber : WORD -> WORD
# ColumnName : BYTE* optional, out -> LPVOID
# BufferLength : SHORT -> short
# NameLength : SHORT* optional, out -> LPVOID
# DataType : SHORT* optional, out -> LPVOID
# ColumnSize : DWORD* optional, out -> LPVOID
# DecimalDigits : SHORT* optional, out -> LPVOID
# Nullable : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い