RasGetCredentialsW
関数シグネチャ
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasGetCredentialsW(
LPCWSTR param0, // optional
LPCWSTR param1,
RASCREDENTIALSW* param2
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| param0 | LPCWSTR | inoptional | 電話帳ファイルのフルパス文字列。NULL指定で既定の電話帳を使用する。 |
| param1 | LPCWSTR | in | 資格情報を取得する対象エントリ名の文字列。 |
| param2 | RASCREDENTIALSW* | inout | 取得した資格情報を受け取るRASCREDENTIALSW構造体へのポインタ。dwMaskで取得項目を指定する。 |
戻り値の型: DWORD
公式ドキュメント
RasGetCredentials 関数は、指定した RAS 電話帳エントリに関連付けられているユーザー資格情報を取得します。(Unicode)
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は次のいずれかのエラー コード、または ルーティングとリモート アクセスのエラー コード もしくは Winerror.h の値です。
| 値 | 意味 |
|---|---|
| 指定された電話帳が見つかりません。 | |
| 指定されたエントリは電話帳に存在しません。 | |
| lpCredentials パラメーターが NULL でした。 | |
| RASCREDENTIALS 構造体の dwSize メンバーが認識できない値です。 |
解説(Remarks)
RasGetCredentials 関数は、指定した電話帳エントリを使用して接続した最後のユーザーの資格情報、またはその電話帳エントリに対して後から RasSetCredentials 関数の呼び出しで指定された資格情報を取得します。
RAS 電話帳エントリに関連付けられている資格情報を安全に取得するには、この関数を使用することをお勧めします。RasGetCredentials は RasGetEntryDialParams 関数に代わるものです。RasGetEntryDialParams は、将来のリリースの Windows ではサポートされない可能性があります。
RasGetCredentials は実際のパスワードを返しません。代わりに、RASCREDENTIALS 構造体の szPassword メンバーには、保存されたパスワードへのハンドルが格納されます。以降の RasSetCredentials および RasDial の呼び出しでは、保存されたパスワードの代わりにこのハンドルを指定してください。このハンドルが渡されると、RasDial は保存されたパスワードを取得して使用します。このハンドルの値は将来のバージョンのオペレーティング システムで変更される可能性があります。この値の内容や形式に依存するコードを記述しないでください。
RASCREDENTIALS の dwMask メンバーは、指定したエントリのパスワードがシステムに保存されている場合に RASCM_Password フラグを含みます。このエントリのパスワードがシステムに保存されていない場合、dwMask に RASCM_Password は含まれません。
Windows 2000/NT: この機能はサポートされていません。
RASCREDENTIALS 構造体の dwMask に RASCM_DefaultCreds フラグが含まれる場合、返される資格情報は、全ユーザー用の接続に対する既定の資格情報です。
事前共有キーを取得するには、RASCREDENTIALS.dwMask フィールドに RASCM_PreSharedKey フラグを使用します。
Windows 2000/NT: この機能はサポートされていません。
次のサンプル コードは、"RasEntryName" 電話帳エントリを作成し、RasSetCredentials を使用してその資格情報を設定した後、RasGetCredentials を使用してその資格情報を取得します。
#include <windows.h>
#include "ras.h"
#include <stdio.h>
#include <tchar.h>
#include "strsafe.h"
#define PHONE_NUMBER_LENGTH 7
#define DEVICE_NAME_LENGTH 5
#define DEVICE_TYPE_LENGTH 5
#define DOMAIN_NAME_LENGTH 9
#define USER_NAME_LENGTH 11
DWORD __cdecl wmain(){
DWORD dwRet = ERROR_SUCCESS;
LPTSTR lpszEntry = L"RasEntryName";
LPTSTR lpszPhoneNumber = L"5555555";
LPTSTR lpszDeviceName = L"Modem";
LPTSTR lpszDeviceType = RASDT_Modem;
LPTSTR lpszDomainName = L"RASDomain";
LPTSTR lpszUserName = L"RASUserName";
/***********************************************************************************************/
// 新しい電話帳エントリを作成する
/***********************************************************************************************/
// RASENTRY 構造体用のヒープ メモリを割り当てる
LPRASENTRY lpentry = (LPRASENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASENTRY));
if (lpentry == NULL){
wprintf(L"HeapAlloc failed!\n");
return 0;
}
// RASENTRY->dwSize メンバーを初期化しないと、以降の RRAS の RasValidateEntryName() や
// RasSetEntryProperties API が失敗する。
lpentry->dwSize = sizeof(RASENTRY);
lpentry->dwFramingProtocol = RASFP_Ppp;
lpentry->dwfOptions = 0;
lpentry->dwType = RASFP_Ppp;
dwRet |= StringCchCopyN(lpentry->szLocalPhoneNumber, RAS_MaxPhoneNumber, lpszPhoneNumber, PHONE_NUMBER_LENGTH);
dwRet |= StringCchCopyN(lpentry->szDeviceName, RAS_MaxDeviceName, lpszDeviceName, DEVICE_NAME_LENGTH);
dwRet |= StringCchCopyN(lpentry->szDeviceType, RAS_MaxDeviceType, lpszDeviceType, DEVICE_TYPE_LENGTH);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RASENTRY structure initialization failed!\n");
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// 新しいエントリの名前を検証する
dwRet = RasValidateEntryName(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasValidateEntryName failed: Error = %d\n", dwRet);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// 新しいエントリを作成し、そのプロパティを設定する
dwRet = RasSetEntryProperties(NULL, lpszEntry, lpentry, lpentry->dwSize, NULL, 0);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasSetEntryProperties failed: Error = %d\n", dwRet);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
/******************************************************************************************/
// 新しいエントリの資格情報を設定し、取得する
/******************************************************************************************/
// RASCREDENTIALS 構造体用のヒープ メモリを割り当てる
LPRASCREDENTIALS lpCred = (LPRASCREDENTIALS) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASCREDENTIALS));
if (lpCred == NULL){
wprintf(L"HeapAlloc failed!\n");
return 0;
}
// RASCREDENTIALS->dwsize メンバーを初期化しないと、以降の RRAS の RasSetCredentials() や
// RasGetCredentials() API が失敗する
lpCred->dwSize = sizeof(RASCREDENTIALS);
// エントリの資格情報は、RasGetCredentials() で取得する前に、まず RasSetCredentials() で
// 設定しておく必要がある。以下の値を使って新しいエントリの資格情報を設定する。
dwRet |= StringCchCopyN(lpCred->szDomain, DNLEN, lpszDomainName, DOMAIN_NAME_LENGTH);
dwRet |= StringCchCopyN(lpCred->szUserName, UNLEN, lpszUserName, USER_NAME_LENGTH);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RASCREDENTIALS structure initialization failed!\n");
HeapFree(GetProcessHeap(), 0, lpCred);
return 0;
}
// ユーザー名、パスワード、ドメインの各資格情報が有効であることを示す
lpCred->dwMask = RASCM_UserName | RASCM_Password | RASCM_Domain;
// 新しく作成したエントリの資格情報を設定する
dwRet = RasSetCredentials(NULL, lpszEntry, lpCred, FALSE);
// 同じ RASCREDENTIALS 構造体を資格情報の 'set' と 'get' の両方に使用しているため、その値を
// クリアする。(これで以降の RasGetCredentials が機能していることを確認できる)
dwRet |= StringCchCopyN(lpCred->szDomain, DNLEN, L"", 0);
dwRet |= StringCchCopyN(lpCred->szUserName, UNLEN, L"", 0);
dwRet |= StringCchCopyN(lpCred->szPassword, UNLEN, L"", 0);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RASCREDENTIALS structure reset failed!\n");
HeapFree(GetProcessHeap(), 0, lpCred);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// 新しく作成したエントリの資格情報を取得する
dwRet = RasGetCredentials(NULL, lpszEntry, lpCred);
if(dwRet == ERROR_SUCCESS){
wprintf(L"The following credentials were retrieved for the entry: %s\n\tUser name: %s\n\tPassword: %s\n\tDomain: %s\n", lpszEntry, lpCred->szUserName, lpCred->szPassword, lpCred->szDomain);
}else{
wprintf(L"RasValidateEntryName failed: Error = %d\n", dwRet);
}
// クリーンアップ: 新しいエントリを削除する
dwRet = RasDeleteEntry(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasDeleteEntry failed: Error = %d\n", dwRet);
}
HeapFree(GetProcessHeap(), 0, lpentry);
HeapFree(GetProcessHeap(), 0, lpCred);
return 0;
}
ras.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして RasGetCredentials を定義しています。エンコードに中立なこのエイリアスを、エンコードに中立でないコードと混在させて使用すると、不一致が生じてコンパイル エラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasGetCredentialsW(
LPCWSTR param0, // optional
LPCWSTR param1,
RASCREDENTIALSW* param2
);[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RasGetCredentialsW(
[MarshalAs(UnmanagedType.LPWStr)] string param0, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string param1, // LPCWSTR
IntPtr param2 // RASCREDENTIALSW* in/out
);<DllImport("RASAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RasGetCredentialsW(
<MarshalAs(UnmanagedType.LPWStr)> param0 As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> param1 As String, ' LPCWSTR
param2 As IntPtr ' RASCREDENTIALSW* in/out
) As UInteger
End Function' param0 : LPCWSTR optional
' param1 : LPCWSTR
' param2 : RASCREDENTIALSW* in/out
Declare PtrSafe Function RasGetCredentialsW Lib "rasapi32" ( _
ByVal param0 As LongPtr, _
ByVal param1 As LongPtr, _
ByVal param2 As LongPtr) As Long
' 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
RasGetCredentialsW = ctypes.windll.rasapi32.RasGetCredentialsW
RasGetCredentialsW.restype = wintypes.DWORD
RasGetCredentialsW.argtypes = [
wintypes.LPCWSTR, # param0 : LPCWSTR optional
wintypes.LPCWSTR, # param1 : LPCWSTR
ctypes.c_void_p, # param2 : RASCREDENTIALSW* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RASAPI32.dll')
RasGetCredentialsW = Fiddle::Function.new(
lib['RasGetCredentialsW'],
[
Fiddle::TYPE_VOIDP, # param0 : LPCWSTR optional
Fiddle::TYPE_VOIDP, # param1 : LPCWSTR
Fiddle::TYPE_VOIDP, # param2 : RASCREDENTIALSW* in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rasapi32")]
extern "system" {
fn RasGetCredentialsW(
param0: *const u16, // LPCWSTR optional
param1: *const u16, // LPCWSTR
param2: *mut RASCREDENTIALSW // RASCREDENTIALSW* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RasGetCredentialsW([MarshalAs(UnmanagedType.LPWStr)] string param0, [MarshalAs(UnmanagedType.LPWStr)] string param1, IntPtr param2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RASAPI32_RasGetCredentialsW' -Namespace Win32 -PassThru
# $api::RasGetCredentialsW(param0, param1, param2)#uselib "RASAPI32.dll"
#func global RasGetCredentialsW "RasGetCredentialsW" wptr, wptr, wptr
; RasGetCredentialsW param0, param1, varptr(param2) ; 戻り値は stat
; param0 : LPCWSTR optional -> "wptr"
; param1 : LPCWSTR -> "wptr"
; param2 : RASCREDENTIALSW* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "RASAPI32.dll" #cfunc global RasGetCredentialsW "RasGetCredentialsW" wstr, wstr, var ; res = RasGetCredentialsW(param0, param1, param2) ; param0 : LPCWSTR optional -> "wstr" ; param1 : LPCWSTR -> "wstr" ; param2 : RASCREDENTIALSW* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "RASAPI32.dll" #cfunc global RasGetCredentialsW "RasGetCredentialsW" wstr, wstr, sptr ; res = RasGetCredentialsW(param0, param1, varptr(param2)) ; param0 : LPCWSTR optional -> "wstr" ; param1 : LPCWSTR -> "wstr" ; param2 : RASCREDENTIALSW* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD RasGetCredentialsW(LPCWSTR param0, LPCWSTR param1, RASCREDENTIALSW* param2) #uselib "RASAPI32.dll" #cfunc global RasGetCredentialsW "RasGetCredentialsW" wstr, wstr, var ; res = RasGetCredentialsW(param0, param1, param2) ; param0 : LPCWSTR optional -> "wstr" ; param1 : LPCWSTR -> "wstr" ; param2 : RASCREDENTIALSW* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD RasGetCredentialsW(LPCWSTR param0, LPCWSTR param1, RASCREDENTIALSW* param2) #uselib "RASAPI32.dll" #cfunc global RasGetCredentialsW "RasGetCredentialsW" wstr, wstr, intptr ; res = RasGetCredentialsW(param0, param1, varptr(param2)) ; param0 : LPCWSTR optional -> "wstr" ; param1 : LPCWSTR -> "wstr" ; param2 : RASCREDENTIALSW* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rasapi32 = windows.NewLazySystemDLL("RASAPI32.dll")
procRasGetCredentialsW = rasapi32.NewProc("RasGetCredentialsW")
)
// param0 (LPCWSTR optional), param1 (LPCWSTR), param2 (RASCREDENTIALSW* in/out)
r1, _, err := procRasGetCredentialsW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param0))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param1))),
uintptr(param2),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RasGetCredentialsW(
param0: PWideChar; // LPCWSTR optional
param1: PWideChar; // LPCWSTR
param2: Pointer // RASCREDENTIALSW* in/out
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasGetCredentialsW';result := DllCall("RASAPI32\RasGetCredentialsW"
, "WStr", param0 ; LPCWSTR optional
, "WStr", param1 ; LPCWSTR
, "Ptr", param2 ; RASCREDENTIALSW* in/out
, "UInt") ; return: DWORD●RasGetCredentialsW(param0, param1, param2) = DLL("RASAPI32.dll", "dword RasGetCredentialsW(char*, char*, void*)")
# 呼び出し: RasGetCredentialsW(param0, param1, param2)
# param0 : LPCWSTR optional -> "char*"
# param1 : LPCWSTR -> "char*"
# param2 : RASCREDENTIALSW* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rasapi32" fn RasGetCredentialsW(
param0: [*c]const u16, // LPCWSTR optional
param1: [*c]const u16, // LPCWSTR
param2: [*c]RASCREDENTIALSW // RASCREDENTIALSW* in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RasGetCredentialsW(
param0: WideCString, # LPCWSTR optional
param1: WideCString, # LPCWSTR
param2: ptr RASCREDENTIALSW # RASCREDENTIALSW* in/out
): uint32 {.importc: "RasGetCredentialsW", stdcall, dynlib: "RASAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rasapi32");
extern(Windows)
uint RasGetCredentialsW(
const(wchar)* param0, // LPCWSTR optional
const(wchar)* param1, // LPCWSTR
RASCREDENTIALSW* param2 // RASCREDENTIALSW* in/out
);ccall((:RasGetCredentialsW, "RASAPI32.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Ptr{RASCREDENTIALSW}),
param0, param1, param2)
# param0 : LPCWSTR optional -> Cwstring
# param1 : LPCWSTR -> Cwstring
# param2 : RASCREDENTIALSW* in/out -> Ptr{RASCREDENTIALSW}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RasGetCredentialsW(
const uint16_t* param0,
const uint16_t* param1,
void* param2);
]]
local rasapi32 = ffi.load("rasapi32")
-- rasapi32.RasGetCredentialsW(param0, param1, param2)
-- param0 : LPCWSTR optional
-- param1 : LPCWSTR
-- param2 : RASCREDENTIALSW* in/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('RASAPI32.dll');
const RasGetCredentialsW = lib.func('__stdcall', 'RasGetCredentialsW', 'uint32_t', ['str16', 'str16', 'void *']);
// RasGetCredentialsW(param0, param1, param2)
// param0 : LPCWSTR optional -> 'str16'
// param1 : LPCWSTR -> 'str16'
// param2 : RASCREDENTIALSW* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RASAPI32.dll", {
RasGetCredentialsW: { parameters: ["buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.RasGetCredentialsW(param0, param1, param2)
// param0 : LPCWSTR optional -> "buffer"
// param1 : LPCWSTR -> "buffer"
// param2 : RASCREDENTIALSW* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RasGetCredentialsW(
const uint16_t* param0,
const uint16_t* param1,
void* param2);
C, "RASAPI32.dll");
// $ffi->RasGetCredentialsW(param0, param1, param2);
// param0 : LPCWSTR optional
// param1 : LPCWSTR
// param2 : RASCREDENTIALSW* 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 Rasapi32 extends StdCallLibrary {
Rasapi32 INSTANCE = Native.load("rasapi32", Rasapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RasGetCredentialsW(
WString param0, // LPCWSTR optional
WString param1, // LPCWSTR
Pointer param2 // RASCREDENTIALSW* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rasapi32")]
lib LibRASAPI32
fun RasGetCredentialsW = RasGetCredentialsW(
param0 : UInt16*, # LPCWSTR optional
param1 : UInt16*, # LPCWSTR
param2 : RASCREDENTIALSW* # RASCREDENTIALSW* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RasGetCredentialsWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>);
typedef RasGetCredentialsWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>);
final RasGetCredentialsW = DynamicLibrary.open('RASAPI32.dll')
.lookupFunction<RasGetCredentialsWNative, RasGetCredentialsWDart>('RasGetCredentialsW');
// param0 : LPCWSTR optional -> Pointer<Utf16>
// param1 : LPCWSTR -> Pointer<Utf16>
// param2 : RASCREDENTIALSW* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RasGetCredentialsW(
param0: PWideChar; // LPCWSTR optional
param1: PWideChar; // LPCWSTR
param2: Pointer // RASCREDENTIALSW* in/out
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasGetCredentialsW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RasGetCredentialsW"
c_RasGetCredentialsW :: CWString -> CWString -> Ptr () -> IO Word32
-- param0 : LPCWSTR optional -> CWString
-- param1 : LPCWSTR -> CWString
-- param2 : RASCREDENTIALSW* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rasgetcredentialsw =
foreign "RasGetCredentialsW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> returning uint32_t)
(* param0 : LPCWSTR optional -> (ptr uint16_t) *)
(* param1 : LPCWSTR -> (ptr uint16_t) *)
(* param2 : RASCREDENTIALSW* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rasapi32 (t "RASAPI32.dll"))
(cffi:use-foreign-library rasapi32)
(cffi:defcfun ("RasGetCredentialsW" ras-get-credentials-w :convention :stdcall) :uint32
(param0 (:string :encoding :utf-16le)) ; LPCWSTR optional
(param1 (:string :encoding :utf-16le)) ; LPCWSTR
(param2 :pointer)) ; RASCREDENTIALSW* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RasGetCredentialsW = Win32::API::More->new('RASAPI32',
'DWORD RasGetCredentialsW(LPCWSTR param0, LPCWSTR param1, LPVOID param2)');
# my $ret = $RasGetCredentialsW->Call($param0, $param1, $param2);
# param0 : LPCWSTR optional -> LPCWSTR
# param1 : LPCWSTR -> LPCWSTR
# param2 : RASCREDENTIALSW* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f RasGetCredentialsA (ANSI版) — RASエントリに保存された認証資格情報を取得する(ANSI版)。
- f RasGetEntryDialParamsW — RASエントリのダイヤルパラメータを取得する(Unicode版)。
- f RasSetCredentialsW — RASエントリの認証資格情報を設定する(Unicode版)。