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

SQLGetCursorNameW

関数
ステートメントのカーソル名を取得する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

SHORT SQLGetCursorNameW(
    void* hstmt,
    WORD* szCursor,   // optional
    SHORT cchCursorMax,
    SHORT* pcchCursor   // optional
);

パラメーター

名前方向説明
hstmtvoid*inoutカーソル名を取得する対象のステートメントハンドル。
szCursorWORD*outoptionalカーソル名を受け取るバッファ。Unicode文字列。
cchCursorMaxSHORTinszCursorバッファの文字数長。
pcchCursorSHORT*outoptionalカーソル名の実際の文字数を受け取るポインタ。NULL可。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLGetCursorNameW(
    void* hstmt,
    WORD* szCursor,   // optional
    SHORT cchCursorMax,
    SHORT* pcchCursor   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetCursorNameW(
    IntPtr hstmt,   // void* in/out
    IntPtr szCursor,   // WORD* optional, out
    short cchCursorMax,   // SHORT
    IntPtr pcchCursor   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetCursorNameW(
    hstmt As IntPtr,   ' void* in/out
    szCursor As IntPtr,   ' WORD* optional, out
    cchCursorMax As Short,   ' SHORT
    pcchCursor As IntPtr   ' SHORT* optional, out
) As Short
End Function
' hstmt : void* in/out
' szCursor : WORD* optional, out
' cchCursorMax : SHORT
' pcchCursor : SHORT* optional, out
Declare PtrSafe Function SQLGetCursorNameW Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal szCursor As LongPtr, _
    ByVal cchCursorMax As Integer, _
    ByVal pcchCursor 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

SQLGetCursorNameW = ctypes.windll.odbc32.SQLGetCursorNameW
SQLGetCursorNameW.restype = ctypes.c_short
SQLGetCursorNameW.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szCursor : WORD* optional, out
    ctypes.c_short,  # cchCursorMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcchCursor : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetCursorNameW = Fiddle::Function.new(
  lib['SQLGetCursorNameW'],
  [
    Fiddle::TYPE_VOIDP,  # hstmt : void* in/out
    Fiddle::TYPE_VOIDP,  # szCursor : WORD* optional, out
    Fiddle::TYPE_SHORT,  # cchCursorMax : SHORT
    Fiddle::TYPE_VOIDP,  # pcchCursor : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetCursorNameW(
        hstmt: *mut (),  // void* in/out
        szCursor: *mut u16,  // WORD* optional, out
        cchCursorMax: i16,  // SHORT
        pcchCursor: *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 SQLGetCursorNameW(IntPtr hstmt, IntPtr szCursor, short cchCursorMax, IntPtr pcchCursor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetCursorNameW' -Namespace Win32 -PassThru
# $api::SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
#uselib "ODBC32.dll"
#func global SQLGetCursorNameW "SQLGetCursorNameW" wptr, wptr, wptr, wptr
; SQLGetCursorNameW hstmt, varptr(szCursor), cchCursorMax, varptr(pcchCursor)   ; 戻り値は stat
; hstmt : void* in/out -> "wptr"
; szCursor : WORD* optional, out -> "wptr"
; cchCursorMax : SHORT -> "wptr"
; pcchCursor : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetCursorNameW "SQLGetCursorNameW" sptr, var, int, var
; res = SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
; hstmt : void* in/out -> "sptr"
; szCursor : WORD* optional, out -> "var"
; cchCursorMax : SHORT -> "int"
; pcchCursor : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetCursorNameW(void* hstmt, WORD* szCursor, SHORT cchCursorMax, SHORT* pcchCursor)
#uselib "ODBC32.dll"
#cfunc global SQLGetCursorNameW "SQLGetCursorNameW" intptr, var, int, var
; res = SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
; hstmt : void* in/out -> "intptr"
; szCursor : WORD* optional, out -> "var"
; cchCursorMax : SHORT -> "int"
; pcchCursor : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetCursorNameW = odbc32.NewProc("SQLGetCursorNameW")
)

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

extern "odbc32" fn SQLGetCursorNameW(
    hstmt: ?*anyopaque, // void* in/out
    szCursor: [*c]u16, // WORD* optional, out
    cchCursorMax: i16, // SHORT
    pcchCursor: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SQLGetCursorNameW(
    hstmt: pointer,  # void* in/out
    szCursor: ptr uint16,  # WORD* optional, out
    cchCursorMax: int16,  # SHORT
    pcchCursor: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLGetCursorNameW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "odbc32");
extern(Windows)
short SQLGetCursorNameW(
    void* hstmt,   // void* in/out
    ushort* szCursor,   // WORD* optional, out
    short cchCursorMax,   // SHORT
    short* pcchCursor   // SHORT* optional, out
);
ccall((:SQLGetCursorNameW, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt16}, Int16, Ptr{Int16}),
      hstmt, szCursor, cchCursorMax, pcchCursor)
# hstmt : void* in/out -> Ptr{Cvoid}
# szCursor : WORD* optional, out -> Ptr{UInt16}
# cchCursorMax : SHORT -> Int16
# pcchCursor : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetCursorNameW(
    void* hstmt,
    uint16_t* szCursor,
    int16_t cchCursorMax,
    int16_t* pcchCursor);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
-- hstmt : void* in/out
-- szCursor : WORD* optional, out
-- cchCursorMax : SHORT
-- pcchCursor : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetCursorNameW = lib.func('__stdcall', 'SQLGetCursorNameW', 'int16_t', ['void *', 'uint16_t *', 'int16_t', 'int16_t *']);
// SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
// hstmt : void* in/out -> 'void *'
// szCursor : WORD* optional, out -> 'uint16_t *'
// cchCursorMax : SHORT -> 'int16_t'
// pcchCursor : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLGetCursorNameW: { parameters: ["pointer", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor)
// hstmt : void* in/out -> "pointer"
// szCursor : WORD* optional, out -> "pointer"
// cchCursorMax : SHORT -> "i16"
// pcchCursor : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetCursorNameW(
    void* hstmt,
    uint16_t* szCursor,
    int16_t cchCursorMax,
    int16_t* pcchCursor);
C, "ODBC32.dll");
// $ffi->SQLGetCursorNameW(hstmt, szCursor, cchCursorMax, pcchCursor);
// hstmt : void* in/out
// szCursor : WORD* optional, out
// cchCursorMax : SHORT
// pcchCursor : 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.UNICODE_OPTIONS);
    short SQLGetCursorNameW(
        Pointer hstmt,   // void* in/out
        ShortByReference szCursor,   // WORD* optional, out
        short cchCursorMax,   // SHORT
        ShortByReference pcchCursor   // SHORT* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("odbc32")]
lib LibODBC32
  fun SQLGetCursorNameW = SQLGetCursorNameW(
    hstmt : Void*,   # void* in/out
    szCursor : UInt16*,   # WORD* optional, out
    cchCursorMax : Int16,   # SHORT
    pcchCursor : 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 SQLGetCursorNameWNative = Int16 Function(Pointer<Void>, Pointer<Uint16>, Int16, Pointer<Int16>);
typedef SQLGetCursorNameWDart = int Function(Pointer<Void>, Pointer<Uint16>, int, Pointer<Int16>);
final SQLGetCursorNameW = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLGetCursorNameWNative, SQLGetCursorNameWDart>('SQLGetCursorNameW');
// hstmt : void* in/out -> Pointer<Void>
// szCursor : WORD* optional, out -> Pointer<Uint16>
// cchCursorMax : SHORT -> Int16
// pcchCursor : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLGetCursorNameW(
  hstmt: Pointer;   // void* in/out
  szCursor: Pointer;   // WORD* optional, out
  cchCursorMax: Smallint;   // SHORT
  pcchCursor: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetCursorNameW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLGetCursorNameW"
  c_SQLGetCursorNameW :: Ptr () -> Ptr Word16 -> Int16 -> Ptr Int16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- szCursor : WORD* optional, out -> Ptr Word16
-- cchCursorMax : SHORT -> Int16
-- pcchCursor : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlgetcursornamew =
  foreign "SQLGetCursorNameW"
    ((ptr void) @-> (ptr uint16_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* szCursor : WORD* optional, out -> (ptr uint16_t) *)
(* cchCursorMax : SHORT -> int16_t *)
(* pcchCursor : 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 ("SQLGetCursorNameW" sqlget-cursor-name-w :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (sz-cursor :pointer)   ; WORD* optional, out
  (cch-cursor-max :int16)   ; SHORT
  (pcch-cursor :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLGetCursorNameW = Win32::API::More->new('ODBC32',
    'short SQLGetCursorNameW(LPVOID hstmt, LPVOID szCursor, short cchCursorMax, LPVOID pcchCursor)');
# my $ret = $SQLGetCursorNameW->Call($hstmt, $szCursor, $cchCursorMax, $pcchCursor);
# hstmt : void* in/out -> LPVOID
# szCursor : WORD* optional, out -> LPVOID
# cchCursorMax : SHORT -> short
# pcchCursor : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い