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

DRMGetServiceLocation

関数
RMSサービスのURL(場所)を取得する。
DLLmsdrm.dll呼出規約winapi

シグネチャ

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

HRESULT DRMGetServiceLocation(
    DWORD hClient,
    DWORD uServiceType,
    DWORD uServiceLocation,
    LPWSTR wszIssuanceLicense,   // optional
    DWORD* puServiceURLLength,
    LPWSTR wszServiceURL   // optional
);

パラメーター

名前型方向説明
hClientDWORDinクライアントセッションのハンドル。このハンドルは DRMCreateClientSession 関数を使用して取得できます。このハンドルは省略可能で、NULL を指定できます。
uServiceTypeDWORDin

必要とするサービスの種類を指定します。次の値のいずれかを指定できます。

DRM_SERVICE_TYPE_ACTIVATION

コンピューターのアクティブ化サービスを取得します。

DRM_SERVICE_TYPE_CERTIFICATION

権利アカウント証明書サービスを取得します。

DRM_SERVICE_TYPE_CLIENTLICENSOR

クライアントライセンサー証明書サービス (オフライン発行用) を取得します。

DRM_SERVICE_TYPE_PUBLISHING

発行ライセンスの署名サービス (オンライン発行用) を取得します。

DRM_SERVICE_TYPE_SILENT

サービスの場所を取得する要求を行うときに、ユーザーインターフェイスのダイアログボックスが表示されないようにします。

uServiceLocationDWORDin

AD RMS サーバーを検索する場所を指定します。次の値のいずれかを指定できます。

DRM_SERVICE_LOCATION_ENTERPRISE

エンタープライズ内で AD RMS サーバーを検索します。

DRM_SERVICE_LOCATION_INTERNET

インターネット上で AD RMS サーバーを検索します。

wszIssuanceLicenseLPWSTRinoptional署名済みの発行ライセンスを含む、null で終わる Unicode 文字列へのポインター。このパラメーターには NULL を指定できます。詳細については、「解説」を参照してください。
puServiceURLLengthDWORD*inout

UINT へのポインター。入力時には、wszServiceURL バッファーのサイズを文字数で格納します。この値には終端の null 文字が含まれます。

関数から制御が戻った後、この UINT には、wszServiceURL バッファーにコピーされた文字数 (終端の null 文字を含む) が格納されます。

wszServiceURL が NULL の場合、この UINT には、サーバー URL に必要な文字数 (終端の null 文字を含む) が格納されます。

wszServiceURLLPWSTRoutoptional

サーバーの URL を受け取る Unicode 文字列バッファーへのポインター。puServiceURLLength パラメーターには、このバッファーのサイズが文字数 (終端の null 文字を含む) で格納されます。

このパラメーターが NULL の場合、puServiceURLLength には、サーバー URL に必要な文字数 (終端の null 文字を含む) が格納されます。

戻り値の型: HRESULT

公式ドキュメント

アクティブ化やライセンス取得など、さまざまな権利管理サービスを実行できるサーバーの URL を取得します。

戻り値

関数が成功した場合は、S_OK を返します。

関数が失敗した場合は、エラーを示す HRESULT 値を返します。取り得る値には次のものがありますが、これらに限定されません。一般的なエラーコードの一覧については、Common HRESULT Values を参照してください。

解説(Remarks)

サービス URL の検出は、uServiceType、uServiceLocation、wszIssuanceLicense の各パラメーターの組み合わせに応じて、次のように行われます。

uServiceType パラメーターに DRM_SERVICE_TYPE_CERTIFICATION または DRM_SERVICE_TYPE_ACTIVATION を設定した場合:

uServiceType パラメーターに DRM_SERVICE_TYPE_PUBLISHING または DRM_SERVICE_TYPE_CLIENTLICENSOR を設定した場合:

関数がレジストリを検索する上記のケースでは、次の一覧にある適切なレジストリキーを追加し、その URL を (default) という名前の文字列値として設定することで、アプリケーションに特定の URL を使用させることができます。URL に .asmx ページを追加しないでください。

レジストリキー 説明
  • 32 ビットコンピューター上の 32 ビットアプリケーション
  • 64 ビットコンピューター上の 64 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDRM\ServiceLocation\Activation
  • 64 ビットコンピューター上の 32 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSDRM\ServiceLocation\Activation
RMS v1.0 では、このレジストリ値にコンピューターのアクティブ化サービスの URL を設定します。この値を証明書発行に使用するには、エンタープライズの証明書発行仮想ルートを設定します。

RMS v1.0 SP1 以降では、この値は証明書発行サービスの検出にのみ使用できます。そのため、権利アカウント仮想ルートの URL (http://ServerName/_wmcs/certification) を設定してください。

  • 32 ビットコンピューター上の 32 ビットアプリケーション
  • 64 ビットコンピューター上の 64 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDRM\ServiceLocation\EnterprisePublishing
  • 64 ビットコンピューター上の 32 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSDRM\ServiceLocation\EnterprisePublishing
このレジストリ値には、エンタープライズネットワーク内で発行ライセンスに署名するサービスの URL を設定します。
  • 32 ビットコンピューター上の 32 ビットアプリケーション
  • 64 ビットコンピューター上の 64 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDRM\ServiceLocation\CloudPublishing
  • 64 ビットコンピューター上の 32 ビットアプリケーション
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSDRM\ServiceLocation\CloudPublishing
このレジストリ値には、インターネット経由で発行ライセンスに署名するサービスの URL を設定します。

取得したデータ用のメモリの割り当てと解放は、アプリケーションが行います。必要なバッファーサイズを調べるには、wszServiceURL パラメーターに NULL を指定して関数を呼び出します。バッファーサイズは puServiceURLLength パラメーターを通じて返されます。

サービス検出のコード例については、OnlineSigning_GetServiceURL.cpp を参照してください。エンドユーザーライセンスの取得についてはサービス検出はありません。これは、その情報を、エンドユーザーライセンスの取得に使用する発行ライセンスに格納できるためです。

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

各言語での呼び出し定義

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

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

DRMGetServiceLocation = ctypes.windll.msdrm.DRMGetServiceLocation
DRMGetServiceLocation.restype = ctypes.c_int
DRMGetServiceLocation.argtypes = [
    wintypes.DWORD,  # hClient : DWORD
    wintypes.DWORD,  # uServiceType : DWORD
    wintypes.DWORD,  # uServiceLocation : DWORD
    wintypes.LPCWSTR,  # wszIssuanceLicense : LPWSTR optional
    ctypes.POINTER(wintypes.DWORD),  # puServiceURLLength : DWORD* in/out
    wintypes.LPWSTR,  # wszServiceURL : LPWSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msdrm = windows.NewLazySystemDLL("msdrm.dll")
	procDRMGetServiceLocation = msdrm.NewProc("DRMGetServiceLocation")
)

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

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

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

foreign import stdcall safe "DRMGetServiceLocation"
  c_DRMGetServiceLocation :: Word32 -> Word32 -> Word32 -> CWString -> Ptr Word32 -> CWString -> IO Int32
-- hClient : DWORD -> Word32
-- uServiceType : DWORD -> Word32
-- uServiceLocation : DWORD -> Word32
-- wszIssuanceLicense : LPWSTR optional -> CWString
-- puServiceURLLength : DWORD* in/out -> Ptr Word32
-- wszServiceURL : LPWSTR optional, out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drmgetservicelocation =
  foreign "DRMGetServiceLocation"
    (uint32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> returning int32_t)
(* hClient : DWORD -> uint32_t *)
(* uServiceType : DWORD -> uint32_t *)
(* uServiceLocation : DWORD -> uint32_t *)
(* wszIssuanceLicense : LPWSTR optional -> (ptr uint16_t) *)
(* puServiceURLLength : DWORD* in/out -> (ptr uint32_t) *)
(* wszServiceURL : LPWSTR optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msdrm (t "msdrm.dll"))
(cffi:use-foreign-library msdrm)

(cffi:defcfun ("DRMGetServiceLocation" drmget-service-location :convention :stdcall) :int32
  (h-client :uint32)   ; DWORD
  (u-service-type :uint32)   ; DWORD
  (u-service-location :uint32)   ; DWORD
  (wsz-issuance-license (:string :encoding :utf-16le))   ; LPWSTR optional
  (pu-service-urllength :pointer)   ; DWORD* in/out
  (wsz-service-url :pointer))   ; LPWSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DRMGetServiceLocation = Win32::API::More->new('msdrm',
    'int DRMGetServiceLocation(DWORD hClient, DWORD uServiceType, DWORD uServiceLocation, LPCWSTR wszIssuanceLicense, LPVOID puServiceURLLength, LPWSTR wszServiceURL)');
# my $ret = $DRMGetServiceLocation->Call($hClient, $uServiceType, $uServiceLocation, $wszIssuanceLicense, $puServiceURLLength, $wszServiceURL);
# hClient : DWORD -> DWORD
# uServiceType : DWORD -> DWORD
# uServiceLocation : DWORD -> DWORD
# wszIssuanceLicense : LPWSTR optional -> LPCWSTR
# puServiceURLLength : DWORD* in/out -> LPVOID
# wszServiceURL : LPWSTR optional, out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目