Win32 API 日本語リファレンス
ホームUI.Controls › DPA_InsertPtr

DPA_InsertPtr

関数
動的ポインタ配列の指定位置にポインタを挿入する。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// COMCTL32.dll
#include <windows.h>

INT DPA_InsertPtr(
    HDPA hdpa,
    INT i,
    void* p   // optional
);

パラメーター

名前方向説明
hdpaHDPAinDPA へのハンドル。
iINTin新しい項目を挿入する位置。
pvoid*inoptional挿入する項目へのポインター。

戻り値の型: INT

公式ドキュメント

動的ポインター配列 (DPA) 内の指定した位置に新しい項目を挿入します。必要に応じて、新しい項目を格納できるように DPA は拡張されます。

戻り値

型: int

新しい項目のインデックスを返します。挿入に失敗した場合は -1 を返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// COMCTL32.dll
#include <windows.h>

INT DPA_InsertPtr(
    HDPA hdpa,
    INT i,
    void* p   // optional
);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern int DPA_InsertPtr(
    IntPtr hdpa,   // HDPA
    int i,   // INT
    IntPtr p   // void* optional
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function DPA_InsertPtr(
    hdpa As IntPtr,   ' HDPA
    i As Integer,   ' INT
    p As IntPtr   ' void* optional
) As Integer
End Function
' hdpa : HDPA
' i : INT
' p : void* optional
Declare PtrSafe Function DPA_InsertPtr Lib "comctl32" ( _
    ByVal hdpa As LongPtr, _
    ByVal i As Long, _
    ByVal p As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DPA_InsertPtr = ctypes.windll.comctl32.DPA_InsertPtr
DPA_InsertPtr.restype = ctypes.c_int
DPA_InsertPtr.argtypes = [
    ctypes.c_ssize_t,  # hdpa : HDPA
    ctypes.c_int,  # i : INT
    ctypes.POINTER(None),  # p : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
DPA_InsertPtr = Fiddle::Function.new(
  lib['DPA_InsertPtr'],
  [
    Fiddle::TYPE_INTPTR_T,  # hdpa : HDPA
    Fiddle::TYPE_INT,  # i : INT
    Fiddle::TYPE_VOIDP,  # p : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn DPA_InsertPtr(
        hdpa: isize,  // HDPA
        i: i32,  // INT
        p: *mut ()  // void* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("COMCTL32.dll")]
public static extern int DPA_InsertPtr(IntPtr hdpa, int i, IntPtr p);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_DPA_InsertPtr' -Namespace Win32 -PassThru
# $api::DPA_InsertPtr(hdpa, i, p)
#uselib "COMCTL32.dll"
#func global DPA_InsertPtr "DPA_InsertPtr" sptr, sptr, sptr
; DPA_InsertPtr hdpa, i, p   ; 戻り値は stat
; hdpa : HDPA -> "sptr"
; i : INT -> "sptr"
; p : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "COMCTL32.dll"
#cfunc global DPA_InsertPtr "DPA_InsertPtr" sptr, int, sptr
; res = DPA_InsertPtr(hdpa, i, p)
; hdpa : HDPA -> "sptr"
; i : INT -> "int"
; p : void* optional -> "sptr"
; INT DPA_InsertPtr(HDPA hdpa, INT i, void* p)
#uselib "COMCTL32.dll"
#cfunc global DPA_InsertPtr "DPA_InsertPtr" intptr, int, intptr
; res = DPA_InsertPtr(hdpa, i, p)
; hdpa : HDPA -> "intptr"
; i : INT -> "int"
; p : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procDPA_InsertPtr = comctl32.NewProc("DPA_InsertPtr")
)

// hdpa (HDPA), i (INT), p (void* optional)
r1, _, err := procDPA_InsertPtr.Call(
	uintptr(hdpa),
	uintptr(i),
	uintptr(p),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function DPA_InsertPtr(
  hdpa: NativeInt;   // HDPA
  i: Integer;   // INT
  p: Pointer   // void* optional
): Integer; stdcall;
  external 'COMCTL32.dll' name 'DPA_InsertPtr';
result := DllCall("COMCTL32\DPA_InsertPtr"
    , "Ptr", hdpa   ; HDPA
    , "Int", i   ; INT
    , "Ptr", p   ; void* optional
    , "Int")   ; return: INT
●DPA_InsertPtr(hdpa, i, p) = DLL("COMCTL32.dll", "int DPA_InsertPtr(int, int, void*)")
# 呼び出し: DPA_InsertPtr(hdpa, i, p)
# hdpa : HDPA -> "int"
# i : INT -> "int"
# p : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "comctl32" fn DPA_InsertPtr(
    hdpa: isize, // HDPA
    i: i32, // INT
    p: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc DPA_InsertPtr(
    hdpa: int,  # HDPA
    i: int32,  # INT
    p: pointer  # void* optional
): int32 {.importc: "DPA_InsertPtr", stdcall, dynlib: "COMCTL32.dll".}
pragma(lib, "comctl32");
extern(Windows)
int DPA_InsertPtr(
    ptrdiff_t hdpa,   // HDPA
    int i,   // INT
    void* p   // void* optional
);
ccall((:DPA_InsertPtr, "COMCTL32.dll"), stdcall, Int32,
      (Int, Int32, Ptr{Cvoid}),
      hdpa, i, p)
# hdpa : HDPA -> Int
# i : INT -> Int32
# p : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DPA_InsertPtr(
    intptr_t hdpa,
    int32_t i,
    void* p);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.DPA_InsertPtr(hdpa, i, p)
-- hdpa : HDPA
-- i : INT
-- p : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const DPA_InsertPtr = lib.func('__stdcall', 'DPA_InsertPtr', 'int32_t', ['intptr_t', 'int32_t', 'void *']);
// DPA_InsertPtr(hdpa, i, p)
// hdpa : HDPA -> 'intptr_t'
// i : INT -> 'int32_t'
// p : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("COMCTL32.dll", {
  DPA_InsertPtr: { parameters: ["isize", "i32", "pointer"], result: "i32" },
});
// lib.symbols.DPA_InsertPtr(hdpa, i, p)
// hdpa : HDPA -> "isize"
// i : INT -> "i32"
// p : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DPA_InsertPtr(
    intptr_t hdpa,
    int32_t i,
    void* p);
C, "COMCTL32.dll");
// $ffi->DPA_InsertPtr(hdpa, i, p);
// hdpa : HDPA
// i : INT
// p : void* optional
// 構造体/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 Comctl32 extends StdCallLibrary {
    Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
    int DPA_InsertPtr(
        long hdpa,   // HDPA
        int i,   // INT
        Pointer p   // void* optional
    );
}
@[Link("comctl32")]
lib LibCOMCTL32
  fun DPA_InsertPtr = DPA_InsertPtr(
    hdpa : LibC::SSizeT,   # HDPA
    i : Int32,   # INT
    p : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DPA_InsertPtrNative = Int32 Function(IntPtr, Int32, Pointer<Void>);
typedef DPA_InsertPtrDart = int Function(int, int, Pointer<Void>);
final DPA_InsertPtr = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<DPA_InsertPtrNative, DPA_InsertPtrDart>('DPA_InsertPtr');
// hdpa : HDPA -> IntPtr
// i : INT -> Int32
// p : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DPA_InsertPtr(
  hdpa: NativeInt;   // HDPA
  i: Integer;   // INT
  p: Pointer   // void* optional
): Integer; stdcall;
  external 'COMCTL32.dll' name 'DPA_InsertPtr';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DPA_InsertPtr"
  c_DPA_InsertPtr :: CIntPtr -> Int32 -> Ptr () -> IO Int32
-- hdpa : HDPA -> CIntPtr
-- i : INT -> Int32
-- p : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dpa_insertptr =
  foreign "DPA_InsertPtr"
    (intptr_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* hdpa : HDPA -> intptr_t *)
(* i : INT -> int32_t *)
(* p : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("DPA_InsertPtr" dpa-insert-ptr :convention :stdcall) :int32
  (hdpa :int64)   ; HDPA
  (i :int32)   ; INT
  (p :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DPA_InsertPtr = Win32::API::More->new('COMCTL32',
    'int DPA_InsertPtr(LPARAM hdpa, int i, LPVOID p)');
# my $ret = $DPA_InsertPtr->Call($hdpa, $i, $p);
# hdpa : HDPA -> LPARAM
# i : INT -> int
# p : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。