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

SQLErrorA

関数
直前のODBC関数の診断エラー情報を取得する(ANSI)。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLErrorA(
    void* henv,
    void* hdbc,
    void* hstmt,
    BYTE* szSqlState,
    INT* pfNativeError,   // optional
    BYTE* szErrorMsg,   // optional
    SHORT cbErrorMsgMax,
    SHORT* pcbErrorMsg   // optional
);

パラメーター

名前方向説明
henvvoid*inout環境ハンドル。エラー取得対象。不要ならSQL_NULL_HENV。
hdbcvoid*inout接続ハンドル。エラー取得対象。不要ならSQL_NULL_HDBC。
hstmtvoid*inoutステートメントハンドル。エラー取得対象。不要ならSQL_NULL_HSTMT。
szSqlStateBYTE*out5文字のSQLSTATEコードを受け取るバッファ。出力用。
pfNativeErrorINT*outoptionalドライバ固有のネイティブエラーコードを受け取るポインタ。
szErrorMsgBYTE*outoptionalエラーメッセージ本文を受け取るバッファ。出力用。
cbErrorMsgMaxSHORTinszErrorMsgバッファのバイト長。
pcbErrorMsgSHORT*outoptional実際に返されたメッセージのバイト長を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLErrorA(
    void* henv,
    void* hdbc,
    void* hstmt,
    BYTE* szSqlState,
    INT* pfNativeError,   // optional
    BYTE* szErrorMsg,   // optional
    SHORT cbErrorMsgMax,
    SHORT* pcbErrorMsg   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLErrorA(
    IntPtr henv,   // void* in/out
    IntPtr hdbc,   // void* in/out
    IntPtr hstmt,   // void* in/out
    IntPtr szSqlState,   // BYTE* out
    IntPtr pfNativeError,   // INT* optional, out
    IntPtr szErrorMsg,   // BYTE* optional, out
    short cbErrorMsgMax,   // SHORT
    IntPtr pcbErrorMsg   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLErrorA(
    henv As IntPtr,   ' void* in/out
    hdbc As IntPtr,   ' void* in/out
    hstmt As IntPtr,   ' void* in/out
    szSqlState As IntPtr,   ' BYTE* out
    pfNativeError As IntPtr,   ' INT* optional, out
    szErrorMsg As IntPtr,   ' BYTE* optional, out
    cbErrorMsgMax As Short,   ' SHORT
    pcbErrorMsg As IntPtr   ' SHORT* optional, out
) As Short
End Function
' henv : void* in/out
' hdbc : void* in/out
' hstmt : void* in/out
' szSqlState : BYTE* out
' pfNativeError : INT* optional, out
' szErrorMsg : BYTE* optional, out
' cbErrorMsgMax : SHORT
' pcbErrorMsg : SHORT* optional, out
Declare PtrSafe Function SQLErrorA Lib "odbc32" ( _
    ByVal henv As LongPtr, _
    ByVal hdbc As LongPtr, _
    ByVal hstmt As LongPtr, _
    ByVal szSqlState As LongPtr, _
    ByVal pfNativeError As LongPtr, _
    ByVal szErrorMsg As LongPtr, _
    ByVal cbErrorMsgMax As Integer, _
    ByVal pcbErrorMsg As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLErrorA = ctypes.windll.odbc32.SQLErrorA
SQLErrorA.restype = ctypes.c_short
SQLErrorA.argtypes = [
    ctypes.POINTER(None),  # henv : void* in/out
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # szSqlState : BYTE* out
    ctypes.POINTER(ctypes.c_int),  # pfNativeError : INT* optional, out
    ctypes.POINTER(ctypes.c_ubyte),  # szErrorMsg : BYTE* optional, out
    ctypes.c_short,  # cbErrorMsgMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbErrorMsg : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLErrorA = odbc32.NewProc("SQLErrorA")
)

// henv (void* in/out), hdbc (void* in/out), hstmt (void* in/out), szSqlState (BYTE* out), pfNativeError (INT* optional, out), szErrorMsg (BYTE* optional, out), cbErrorMsgMax (SHORT), pcbErrorMsg (SHORT* optional, out)
r1, _, err := procSQLErrorA.Call(
	uintptr(henv),
	uintptr(hdbc),
	uintptr(hstmt),
	uintptr(szSqlState),
	uintptr(pfNativeError),
	uintptr(szErrorMsg),
	uintptr(cbErrorMsgMax),
	uintptr(pcbErrorMsg),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLErrorA(
  henv: Pointer;   // void* in/out
  hdbc: Pointer;   // void* in/out
  hstmt: Pointer;   // void* in/out
  szSqlState: Pointer;   // BYTE* out
  pfNativeError: Pointer;   // INT* optional, out
  szErrorMsg: Pointer;   // BYTE* optional, out
  cbErrorMsgMax: Smallint;   // SHORT
  pcbErrorMsg: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLErrorA';
result := DllCall("ODBC32\SQLErrorA"
    , "Ptr", henv   ; void* in/out
    , "Ptr", hdbc   ; void* in/out
    , "Ptr", hstmt   ; void* in/out
    , "Ptr", szSqlState   ; BYTE* out
    , "Ptr", pfNativeError   ; INT* optional, out
    , "Ptr", szErrorMsg   ; BYTE* optional, out
    , "Short", cbErrorMsgMax   ; SHORT
    , "Ptr", pcbErrorMsg   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLErrorA(henv, hdbc, hstmt, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg) = DLL("ODBC32.dll", "int SQLErrorA(void*, void*, void*, void*, void*, void*, int, void*)")
# 呼び出し: SQLErrorA(henv, hdbc, hstmt, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
# henv : void* in/out -> "void*"
# hdbc : void* in/out -> "void*"
# hstmt : void* in/out -> "void*"
# szSqlState : BYTE* out -> "void*"
# pfNativeError : INT* optional, out -> "void*"
# szErrorMsg : BYTE* optional, out -> "void*"
# cbErrorMsgMax : SHORT -> "int"
# pcbErrorMsg : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

foreign import stdcall safe "SQLErrorA"
  c_SQLErrorA :: Ptr () -> Ptr () -> Ptr () -> Ptr Word8 -> Ptr Int32 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- henv : void* in/out -> Ptr ()
-- hdbc : void* in/out -> Ptr ()
-- hstmt : void* in/out -> Ptr ()
-- szSqlState : BYTE* out -> Ptr Word8
-- pfNativeError : INT* optional, out -> Ptr Int32
-- szErrorMsg : BYTE* optional, out -> Ptr Word8
-- cbErrorMsgMax : SHORT -> Int16
-- pcbErrorMsg : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlerrora =
  foreign "SQLErrorA"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> (ptr int32_t) @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* henv : void* in/out -> (ptr void) *)
(* hdbc : void* in/out -> (ptr void) *)
(* hstmt : void* in/out -> (ptr void) *)
(* szSqlState : BYTE* out -> (ptr uint8_t) *)
(* pfNativeError : INT* optional, out -> (ptr int32_t) *)
(* szErrorMsg : BYTE* optional, out -> (ptr uint8_t) *)
(* cbErrorMsgMax : SHORT -> int16_t *)
(* pcbErrorMsg : 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 ("SQLErrorA" sqlerror-a :convention :stdcall) :int16
  (henv :pointer)   ; void* in/out
  (hdbc :pointer)   ; void* in/out
  (hstmt :pointer)   ; void* in/out
  (sz-sql-state :pointer)   ; BYTE* out
  (pf-native-error :pointer)   ; INT* optional, out
  (sz-error-msg :pointer)   ; BYTE* optional, out
  (cb-error-msg-max :int16)   ; SHORT
  (pcb-error-msg :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLErrorA = Win32::API::More->new('ODBC32',
    'short SQLErrorA(LPVOID henv, LPVOID hdbc, LPVOID hstmt, LPVOID szSqlState, LPVOID pfNativeError, LPVOID szErrorMsg, short cbErrorMsgMax, LPVOID pcbErrorMsg)');
# my $ret = $SQLErrorA->Call($henv, $hdbc, $hstmt, $szSqlState, $pfNativeError, $szErrorMsg, $cbErrorMsgMax, $pcbErrorMsg);
# henv : void* in/out -> LPVOID
# hdbc : void* in/out -> LPVOID
# hstmt : void* in/out -> LPVOID
# szSqlState : BYTE* out -> LPVOID
# pfNativeError : INT* optional, out -> LPVOID
# szErrorMsg : BYTE* optional, out -> LPVOID
# cbErrorMsgMax : SHORT -> short
# pcbErrorMsg : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い