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

SQLGetDiagFieldW

関数
診断レコードの指定フィールド値を取得する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLGetDiagFieldW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    SHORT fDiagField,
    void* rgbDiagInfo,   // optional
    SHORT cbBufferLength,
    SHORT* pcbStringLength   // optional
);

パラメーター

名前方向
fHandleTypeSHORTin
handlevoid*inout
iRecordSHORTin
fDiagFieldSHORTin
rgbDiagInfovoid*outoptional
cbBufferLengthSHORTin
pcbStringLengthSHORT*outoptional

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLGetDiagFieldW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    SHORT fDiagField,
    void* rgbDiagInfo,   // optional
    SHORT cbBufferLength,
    SHORT* pcbStringLength   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetDiagFieldW(
    short fHandleType,   // SHORT
    IntPtr handle,   // void* in/out
    short iRecord,   // SHORT
    short fDiagField,   // SHORT
    IntPtr rgbDiagInfo,   // void* optional, out
    short cbBufferLength,   // SHORT
    IntPtr pcbStringLength   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetDiagFieldW(
    fHandleType As Short,   ' SHORT
    handle As IntPtr,   ' void* in/out
    iRecord As Short,   ' SHORT
    fDiagField As Short,   ' SHORT
    rgbDiagInfo As IntPtr,   ' void* optional, out
    cbBufferLength As Short,   ' SHORT
    pcbStringLength As IntPtr   ' SHORT* optional, out
) As Short
End Function
' fHandleType : SHORT
' handle : void* in/out
' iRecord : SHORT
' fDiagField : SHORT
' rgbDiagInfo : void* optional, out
' cbBufferLength : SHORT
' pcbStringLength : SHORT* optional, out
Declare PtrSafe Function SQLGetDiagFieldW Lib "odbc32" ( _
    ByVal fHandleType As Integer, _
    ByVal handle As LongPtr, _
    ByVal iRecord As Integer, _
    ByVal fDiagField As Integer, _
    ByVal rgbDiagInfo As LongPtr, _
    ByVal cbBufferLength As Integer, _
    ByVal pcbStringLength As LongPtr) As Integer
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLGetDiagFieldW = ctypes.windll.odbc32.SQLGetDiagFieldW
SQLGetDiagFieldW.restype = ctypes.c_short
SQLGetDiagFieldW.argtypes = [
    ctypes.c_short,  # fHandleType : SHORT
    ctypes.POINTER(None),  # handle : void* in/out
    ctypes.c_short,  # iRecord : SHORT
    ctypes.c_short,  # fDiagField : SHORT
    ctypes.POINTER(None),  # rgbDiagInfo : void* optional, out
    ctypes.c_short,  # cbBufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbStringLength : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDiagFieldW = Fiddle::Function.new(
  lib['SQLGetDiagFieldW'],
  [
    Fiddle::TYPE_SHORT,  # fHandleType : SHORT
    Fiddle::TYPE_VOIDP,  # handle : void* in/out
    Fiddle::TYPE_SHORT,  # iRecord : SHORT
    Fiddle::TYPE_SHORT,  # fDiagField : SHORT
    Fiddle::TYPE_VOIDP,  # rgbDiagInfo : void* optional, out
    Fiddle::TYPE_SHORT,  # cbBufferLength : SHORT
    Fiddle::TYPE_VOIDP,  # pcbStringLength : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetDiagFieldW(
        fHandleType: i16,  // SHORT
        handle: *mut (),  // void* in/out
        iRecord: i16,  // SHORT
        fDiagField: i16,  // SHORT
        rgbDiagInfo: *mut (),  // void* optional, out
        cbBufferLength: i16,  // SHORT
        pcbStringLength: *mut i16  // SHORT* optional, out
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLGetDiagFieldW(short fHandleType, IntPtr handle, short iRecord, short fDiagField, IntPtr rgbDiagInfo, short cbBufferLength, IntPtr pcbStringLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagFieldW' -Namespace Win32 -PassThru
# $api::SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
#uselib "ODBC32.dll"
#func global SQLGetDiagFieldW "SQLGetDiagFieldW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SQLGetDiagFieldW fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, varptr(pcbStringLength)   ; 戻り値は stat
; fHandleType : SHORT -> "wptr"
; handle : void* in/out -> "wptr"
; iRecord : SHORT -> "wptr"
; fDiagField : SHORT -> "wptr"
; rgbDiagInfo : void* optional, out -> "wptr"
; cbBufferLength : SHORT -> "wptr"
; pcbStringLength : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldW "SQLGetDiagFieldW" int, sptr, int, int, sptr, int, var
; res = SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "sptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "sptr"
; cbBufferLength : SHORT -> "int"
; pcbStringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetDiagFieldW(SHORT fHandleType, void* handle, SHORT iRecord, SHORT fDiagField, void* rgbDiagInfo, SHORT cbBufferLength, SHORT* pcbStringLength)
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldW "SQLGetDiagFieldW" int, intptr, int, int, intptr, int, var
; res = SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "intptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "intptr"
; cbBufferLength : SHORT -> "int"
; pcbStringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDiagFieldW = odbc32.NewProc("SQLGetDiagFieldW")
)

// fHandleType (SHORT), handle (void* in/out), iRecord (SHORT), fDiagField (SHORT), rgbDiagInfo (void* optional, out), cbBufferLength (SHORT), pcbStringLength (SHORT* optional, out)
r1, _, err := procSQLGetDiagFieldW.Call(
	uintptr(fHandleType),
	uintptr(handle),
	uintptr(iRecord),
	uintptr(fDiagField),
	uintptr(rgbDiagInfo),
	uintptr(cbBufferLength),
	uintptr(pcbStringLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLGetDiagFieldW(
  fHandleType: Smallint;   // SHORT
  handle: Pointer;   // void* in/out
  iRecord: Smallint;   // SHORT
  fDiagField: Smallint;   // SHORT
  rgbDiagInfo: Pointer;   // void* optional, out
  cbBufferLength: Smallint;   // SHORT
  pcbStringLength: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagFieldW';
result := DllCall("ODBC32\SQLGetDiagFieldW"
    , "Short", fHandleType   ; SHORT
    , "Ptr", handle   ; void* in/out
    , "Short", iRecord   ; SHORT
    , "Short", fDiagField   ; SHORT
    , "Ptr", rgbDiagInfo   ; void* optional, out
    , "Short", cbBufferLength   ; SHORT
    , "Ptr", pcbStringLength   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength) = DLL("ODBC32.dll", "int SQLGetDiagFieldW(int, void*, int, int, void*, int, void*)")
# 呼び出し: SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
# fHandleType : SHORT -> "int"
# handle : void* in/out -> "void*"
# iRecord : SHORT -> "int"
# fDiagField : SHORT -> "int"
# rgbDiagInfo : void* optional, out -> "void*"
# cbBufferLength : SHORT -> "int"
# pcbStringLength : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。