Win32 API 日本語リファレンス
ホームData.RightsManagement › DRMCreateLicenseStorageSession

DRMCreateLicenseStorageSession

関数
RMSのライセンス保存セッションを作成する。
DLLmsdrm.dll呼出規約winapi

シグネチャ

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

HRESULT DRMCreateLicenseStorageSession(
    DWORD hEnv,
    DWORD hDefaultLibrary,
    DWORD hClient,
    DWORD uFlags,
    LPWSTR wszIssuanceLicense,
    DWORD* phLicenseStorage
);

パラメーター

名前方向説明
hEnvDWORDin対象の環境ハンドル。
hDefaultLibraryDWORDin既定ライブラリのハンドル。
hClientDWORDin対象のクライアントセッションハンドル。
uFlagsDWORDinライセンスストレージセッションの動作を制御するフラグ。
wszIssuanceLicenseLPWSTRin対象の発行ライセンスを示すUnicode文字列。
phLicenseStorageDWORD*inout生成されたライセンスストレージセッションのハンドルを受け取る出力先。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DRMCreateLicenseStorageSession(
    DWORD hEnv,
    DWORD hDefaultLibrary,
    DWORD hClient,
    DWORD uFlags,
    LPWSTR wszIssuanceLicense,
    DWORD* phLicenseStorage
);
[DllImport("msdrm.dll", ExactSpelling = true)]
static extern int DRMCreateLicenseStorageSession(
    uint hEnv,   // DWORD
    uint hDefaultLibrary,   // DWORD
    uint hClient,   // DWORD
    uint uFlags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string wszIssuanceLicense,   // LPWSTR
    ref uint phLicenseStorage   // DWORD* in/out
);
<DllImport("msdrm.dll", ExactSpelling:=True)>
Public Shared Function DRMCreateLicenseStorageSession(
    hEnv As UInteger,   ' DWORD
    hDefaultLibrary As UInteger,   ' DWORD
    hClient As UInteger,   ' DWORD
    uFlags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> wszIssuanceLicense As String,   ' LPWSTR
    ByRef phLicenseStorage As UInteger   ' DWORD* in/out
) As Integer
End Function
' hEnv : DWORD
' hDefaultLibrary : DWORD
' hClient : DWORD
' uFlags : DWORD
' wszIssuanceLicense : LPWSTR
' phLicenseStorage : DWORD* in/out
Declare PtrSafe Function DRMCreateLicenseStorageSession Lib "msdrm" ( _
    ByVal hEnv As Long, _
    ByVal hDefaultLibrary As Long, _
    ByVal hClient As Long, _
    ByVal uFlags As Long, _
    ByVal wszIssuanceLicense As LongPtr, _
    ByRef phLicenseStorage As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DRMCreateLicenseStorageSession = ctypes.windll.msdrm.DRMCreateLicenseStorageSession
DRMCreateLicenseStorageSession.restype = ctypes.c_int
DRMCreateLicenseStorageSession.argtypes = [
    wintypes.DWORD,  # hEnv : DWORD
    wintypes.DWORD,  # hDefaultLibrary : DWORD
    wintypes.DWORD,  # hClient : DWORD
    wintypes.DWORD,  # uFlags : DWORD
    wintypes.LPCWSTR,  # wszIssuanceLicense : LPWSTR
    ctypes.POINTER(wintypes.DWORD),  # phLicenseStorage : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msdrm.dll')
DRMCreateLicenseStorageSession = Fiddle::Function.new(
  lib['DRMCreateLicenseStorageSession'],
  [
    -Fiddle::TYPE_INT,  # hEnv : DWORD
    -Fiddle::TYPE_INT,  # hDefaultLibrary : DWORD
    -Fiddle::TYPE_INT,  # hClient : DWORD
    -Fiddle::TYPE_INT,  # uFlags : DWORD
    Fiddle::TYPE_VOIDP,  # wszIssuanceLicense : LPWSTR
    Fiddle::TYPE_VOIDP,  # phLicenseStorage : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "msdrm")]
extern "system" {
    fn DRMCreateLicenseStorageSession(
        hEnv: u32,  // DWORD
        hDefaultLibrary: u32,  // DWORD
        hClient: u32,  // DWORD
        uFlags: u32,  // DWORD
        wszIssuanceLicense: *mut u16,  // LPWSTR
        phLicenseStorage: *mut u32  // DWORD* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msdrm.dll")]
public static extern int DRMCreateLicenseStorageSession(uint hEnv, uint hDefaultLibrary, uint hClient, uint uFlags, [MarshalAs(UnmanagedType.LPWStr)] string wszIssuanceLicense, ref uint phLicenseStorage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msdrm_DRMCreateLicenseStorageSession' -Namespace Win32 -PassThru
# $api::DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
#uselib "msdrm.dll"
#func global DRMCreateLicenseStorageSession "DRMCreateLicenseStorageSession" sptr, sptr, sptr, sptr, sptr, sptr
; DRMCreateLicenseStorageSession hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, varptr(phLicenseStorage)   ; 戻り値は stat
; hEnv : DWORD -> "sptr"
; hDefaultLibrary : DWORD -> "sptr"
; hClient : DWORD -> "sptr"
; uFlags : DWORD -> "sptr"
; wszIssuanceLicense : LPWSTR -> "sptr"
; phLicenseStorage : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msdrm.dll"
#cfunc global DRMCreateLicenseStorageSession "DRMCreateLicenseStorageSession" int, int, int, int, wstr, var
; res = DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
; hEnv : DWORD -> "int"
; hDefaultLibrary : DWORD -> "int"
; hClient : DWORD -> "int"
; uFlags : DWORD -> "int"
; wszIssuanceLicense : LPWSTR -> "wstr"
; phLicenseStorage : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DRMCreateLicenseStorageSession(DWORD hEnv, DWORD hDefaultLibrary, DWORD hClient, DWORD uFlags, LPWSTR wszIssuanceLicense, DWORD* phLicenseStorage)
#uselib "msdrm.dll"
#cfunc global DRMCreateLicenseStorageSession "DRMCreateLicenseStorageSession" int, int, int, int, wstr, var
; res = DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
; hEnv : DWORD -> "int"
; hDefaultLibrary : DWORD -> "int"
; hClient : DWORD -> "int"
; uFlags : DWORD -> "int"
; wszIssuanceLicense : LPWSTR -> "wstr"
; phLicenseStorage : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msdrm = windows.NewLazySystemDLL("msdrm.dll")
	procDRMCreateLicenseStorageSession = msdrm.NewProc("DRMCreateLicenseStorageSession")
)

// hEnv (DWORD), hDefaultLibrary (DWORD), hClient (DWORD), uFlags (DWORD), wszIssuanceLicense (LPWSTR), phLicenseStorage (DWORD* in/out)
r1, _, err := procDRMCreateLicenseStorageSession.Call(
	uintptr(hEnv),
	uintptr(hDefaultLibrary),
	uintptr(hClient),
	uintptr(uFlags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(wszIssuanceLicense))),
	uintptr(phLicenseStorage),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DRMCreateLicenseStorageSession(
  hEnv: DWORD;   // DWORD
  hDefaultLibrary: DWORD;   // DWORD
  hClient: DWORD;   // DWORD
  uFlags: DWORD;   // DWORD
  wszIssuanceLicense: PWideChar;   // LPWSTR
  phLicenseStorage: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'msdrm.dll' name 'DRMCreateLicenseStorageSession';
result := DllCall("msdrm\DRMCreateLicenseStorageSession"
    , "UInt", hEnv   ; DWORD
    , "UInt", hDefaultLibrary   ; DWORD
    , "UInt", hClient   ; DWORD
    , "UInt", uFlags   ; DWORD
    , "WStr", wszIssuanceLicense   ; LPWSTR
    , "Ptr", phLicenseStorage   ; DWORD* in/out
    , "Int")   ; return: HRESULT
●DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage) = DLL("msdrm.dll", "int DRMCreateLicenseStorageSession(dword, dword, dword, dword, char*, void*)")
# 呼び出し: DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
# hEnv : DWORD -> "dword"
# hDefaultLibrary : DWORD -> "dword"
# hClient : DWORD -> "dword"
# uFlags : DWORD -> "dword"
# wszIssuanceLicense : LPWSTR -> "char*"
# phLicenseStorage : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "msdrm" fn DRMCreateLicenseStorageSession(
    hEnv: u32, // DWORD
    hDefaultLibrary: u32, // DWORD
    hClient: u32, // DWORD
    uFlags: u32, // DWORD
    wszIssuanceLicense: [*c]const u16, // LPWSTR
    phLicenseStorage: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc DRMCreateLicenseStorageSession(
    hEnv: uint32,  # DWORD
    hDefaultLibrary: uint32,  # DWORD
    hClient: uint32,  # DWORD
    uFlags: uint32,  # DWORD
    wszIssuanceLicense: WideCString,  # LPWSTR
    phLicenseStorage: ptr uint32  # DWORD* in/out
): int32 {.importc: "DRMCreateLicenseStorageSession", stdcall, dynlib: "msdrm.dll".}
pragma(lib, "msdrm");
extern(Windows)
int DRMCreateLicenseStorageSession(
    uint hEnv,   // DWORD
    uint hDefaultLibrary,   // DWORD
    uint hClient,   // DWORD
    uint uFlags,   // DWORD
    const(wchar)* wszIssuanceLicense,   // LPWSTR
    uint* phLicenseStorage   // DWORD* in/out
);
ccall((:DRMCreateLicenseStorageSession, "msdrm.dll"), stdcall, Int32,
      (UInt32, UInt32, UInt32, UInt32, Cwstring, Ptr{UInt32}),
      hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
# hEnv : DWORD -> UInt32
# hDefaultLibrary : DWORD -> UInt32
# hClient : DWORD -> UInt32
# uFlags : DWORD -> UInt32
# wszIssuanceLicense : LPWSTR -> Cwstring
# phLicenseStorage : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DRMCreateLicenseStorageSession(
    uint32_t hEnv,
    uint32_t hDefaultLibrary,
    uint32_t hClient,
    uint32_t uFlags,
    const uint16_t* wszIssuanceLicense,
    uint32_t* phLicenseStorage);
]]
local msdrm = ffi.load("msdrm")
-- msdrm.DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
-- hEnv : DWORD
-- hDefaultLibrary : DWORD
-- hClient : DWORD
-- uFlags : DWORD
-- wszIssuanceLicense : LPWSTR
-- phLicenseStorage : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msdrm.dll');
const DRMCreateLicenseStorageSession = lib.func('__stdcall', 'DRMCreateLicenseStorageSession', 'int32_t', ['uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'str16', 'uint32_t *']);
// DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
// hEnv : DWORD -> 'uint32_t'
// hDefaultLibrary : DWORD -> 'uint32_t'
// hClient : DWORD -> 'uint32_t'
// uFlags : DWORD -> 'uint32_t'
// wszIssuanceLicense : LPWSTR -> 'str16'
// phLicenseStorage : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msdrm.dll", {
  DRMCreateLicenseStorageSession: { parameters: ["u32", "u32", "u32", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage)
// hEnv : DWORD -> "u32"
// hDefaultLibrary : DWORD -> "u32"
// hClient : DWORD -> "u32"
// uFlags : DWORD -> "u32"
// wszIssuanceLicense : LPWSTR -> "buffer"
// phLicenseStorage : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DRMCreateLicenseStorageSession(
    uint32_t hEnv,
    uint32_t hDefaultLibrary,
    uint32_t hClient,
    uint32_t uFlags,
    const uint16_t* wszIssuanceLicense,
    uint32_t* phLicenseStorage);
C, "msdrm.dll");
// $ffi->DRMCreateLicenseStorageSession(hEnv, hDefaultLibrary, hClient, uFlags, wszIssuanceLicense, phLicenseStorage);
// hEnv : DWORD
// hDefaultLibrary : DWORD
// hClient : DWORD
// uFlags : DWORD
// wszIssuanceLicense : LPWSTR
// phLicenseStorage : DWORD* in/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 Msdrm extends StdCallLibrary {
    Msdrm INSTANCE = Native.load("msdrm", Msdrm.class);
    int DRMCreateLicenseStorageSession(
        int hEnv,   // DWORD
        int hDefaultLibrary,   // DWORD
        int hClient,   // DWORD
        int uFlags,   // DWORD
        WString wszIssuanceLicense,   // LPWSTR
        IntByReference phLicenseStorage   // DWORD* in/out
    );
}
@[Link("msdrm")]
lib Libmsdrm
  fun DRMCreateLicenseStorageSession = DRMCreateLicenseStorageSession(
    hEnv : UInt32,   # DWORD
    hDefaultLibrary : UInt32,   # DWORD
    hClient : UInt32,   # DWORD
    uFlags : UInt32,   # DWORD
    wszIssuanceLicense : UInt16*,   # LPWSTR
    phLicenseStorage : UInt32*   # DWORD* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DRMCreateLicenseStorageSessionNative = Int32 Function(Uint32, Uint32, Uint32, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef DRMCreateLicenseStorageSessionDart = int Function(int, int, int, int, Pointer<Utf16>, Pointer<Uint32>);
final DRMCreateLicenseStorageSession = DynamicLibrary.open('msdrm.dll')
    .lookupFunction<DRMCreateLicenseStorageSessionNative, DRMCreateLicenseStorageSessionDart>('DRMCreateLicenseStorageSession');
// hEnv : DWORD -> Uint32
// hDefaultLibrary : DWORD -> Uint32
// hClient : DWORD -> Uint32
// uFlags : DWORD -> Uint32
// wszIssuanceLicense : LPWSTR -> Pointer<Utf16>
// phLicenseStorage : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DRMCreateLicenseStorageSession(
  hEnv: DWORD;   // DWORD
  hDefaultLibrary: DWORD;   // DWORD
  hClient: DWORD;   // DWORD
  uFlags: DWORD;   // DWORD
  wszIssuanceLicense: PWideChar;   // LPWSTR
  phLicenseStorage: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'msdrm.dll' name 'DRMCreateLicenseStorageSession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DRMCreateLicenseStorageSession"
  c_DRMCreateLicenseStorageSession :: Word32 -> Word32 -> Word32 -> Word32 -> CWString -> Ptr Word32 -> IO Int32
-- hEnv : DWORD -> Word32
-- hDefaultLibrary : DWORD -> Word32
-- hClient : DWORD -> Word32
-- uFlags : DWORD -> Word32
-- wszIssuanceLicense : LPWSTR -> CWString
-- phLicenseStorage : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drmcreatelicensestoragesession =
  foreign "DRMCreateLicenseStorageSession"
    (uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hEnv : DWORD -> uint32_t *)
(* hDefaultLibrary : DWORD -> uint32_t *)
(* hClient : DWORD -> uint32_t *)
(* uFlags : DWORD -> uint32_t *)
(* wszIssuanceLicense : LPWSTR -> (ptr uint16_t) *)
(* phLicenseStorage : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msdrm (t "msdrm.dll"))
(cffi:use-foreign-library msdrm)

(cffi:defcfun ("DRMCreateLicenseStorageSession" drmcreate-license-storage-session :convention :stdcall) :int32
  (h-env :uint32)   ; DWORD
  (h-default-library :uint32)   ; DWORD
  (h-client :uint32)   ; DWORD
  (u-flags :uint32)   ; DWORD
  (wsz-issuance-license (:string :encoding :utf-16le))   ; LPWSTR
  (ph-license-storage :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DRMCreateLicenseStorageSession = Win32::API::More->new('msdrm',
    'int DRMCreateLicenseStorageSession(DWORD hEnv, DWORD hDefaultLibrary, DWORD hClient, DWORD uFlags, LPCWSTR wszIssuanceLicense, LPVOID phLicenseStorage)');
# my $ret = $DRMCreateLicenseStorageSession->Call($hEnv, $hDefaultLibrary, $hClient, $uFlags, $wszIssuanceLicense, $phLicenseStorage);
# hEnv : DWORD -> DWORD
# hDefaultLibrary : DWORD -> DWORD
# hClient : DWORD -> DWORD
# uFlags : DWORD -> DWORD
# wszIssuanceLicense : LPWSTR -> LPCWSTR
# phLicenseStorage : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。