ホーム › NetworkManagement.WiFi › WlanGetProfileCustomUserData
WlanGetProfileCustomUserData
関数無線LANプロファイルのアプリ独自カスタムデータを取得する。
シグネチャ
// wlanapi.dll
#include <windows.h>
DWORD WlanGetProfileCustomUserData(
HANDLE hClientHandle,
const GUID* pInterfaceGuid,
LPCWSTR strProfileName,
void* pReserved, // optional
DWORD* pdwDataSize,
BYTE** ppData
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hClientHandle | HANDLE | in | クライアントのセッションハンドル。事前に WlanOpenHandle 関数を呼び出して取得します。 |
| pInterfaceGuid | GUID* | in | ワイヤレス LAN インターフェイスの GUID へのポインター。 |
| strProfileName | LPCWSTR | in | カスタムユーザーデータが関連付けられているプロファイルの名前。プロファイル名では大文字と小文字が区別されます。この文字列は NULL で終端されている必要があります。 |
| pReserved | void* | optional | 将来の使用のために予約されています。NULL を設定する必要があります。 |
| pdwDataSize | DWORD* | out | ppData パラメーターが指すユーザーデータバッファーのサイズ (バイト単位)。 |
| ppData | BYTE** | out | ユーザーデータへのポインター。 |
戻り値の型: DWORD
公式ドキュメント
ワイヤレスプロファイルに関連付けられたカスタムユーザーデータを取得します。
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は次のいずれかのリターンコードになることがあります。
| リターンコード | 説明 |
|---|---|
| 指定されたファイルが見つかりません。指定されたプロファイルにユーザーのカスタムデータが存在しない場合、このエラーが返されます。 | |
| hClientHandle パラメーターが NULL または無効である、pInterfaceGuid パラメーターが NULL である、strProfileName パラメーターが NULL である、pReserved パラメーターが NULL でない、pdwDataSize パラメーターが 0 である、または ppData パラメーターが NULL です。 | |
| 指定されたファイルが見つかりません。指定されたプロファイルにカスタムユーザーデータが存在しない場合、このエラーが返されます。 | |
| ハンドル hClientHandle がハンドルテーブル内に見つかりませんでした。 | |
| この関数がサポートされていないプラットフォームから呼び出されました。この値は、Windows XP SP3 のクライアント、または Windows XP SP2 用 Wireless LAN API のクライアントからこの関数が呼び出された場合に返されます。 | |
|
さまざまなエラーコード。 |
解説(Remarks)
Native Wifi 自動構成サービスが使用するすべてのワイヤレス WLAN プロファイルについて、Windows はカスタムユーザーデータという概念を保持しています。このカスタムユーザーデータは当初は存在しませんが、WlanSetProfileCustomUserData 関数を呼び出して設定できます。WlanSetProfile 関数を呼び出してプロファイルを変更すると、そのたびにカスタムユーザーデータは空にリセットされます。
カスタムユーザーデータをいったん設定すると、WlanGetProfileCustomUserData 関数を使用してそのデータにアクセスできます。
呼び出し元は、ppData パラメーターが指すバッファーに割り当てられたメモリを WlanFreeMemory 関数を使用して解放する必要があります。
例
次の例では、ローカルコンピューター上のワイヤレス LAN インターフェイスを列挙し、続いて各ワイヤレス LAN インターフェイスについて、特定のワイヤレスプロファイルのカスタムユーザーデータ情報の取得を試みます。取得したユーザーカスタムデータのサイズが出力されます。
メモ ワイヤレス LAN サービスがインストールされ、開始されていない場合、この例は Windows Server 2008 および Windows Server 2008 R2 では読み込みに失敗します。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>
#include <stdio.h>
#include <stdlib.h>
// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")
int _cdecl wmain(int argc, WCHAR **argv)
{
// Declare and initialize variables.
HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = {0};
unsigned int i;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
LPCWSTR pProfileName = NULL;
PBYTE pProfileData = NULL;
DWORD dwDataSize = 0;
// Validate the parameters
if (argc < 2) {
wprintf(L"usage: %s <profile>\n", argv[0]);
wprintf(L" Gets a wireless profile\n");
wprintf(L" Example\n");
wprintf(L" %s \"Default Wireless\"\n", argv[0]);
exit(1);
}
pProfileName = argv[1];
wprintf(L"Custom user data information for profile: %ws\n\n", pProfileName);
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
} else {
wprintf(L"WLAN_INTERFACE_INFO_LIST for this system\n");
wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
wprintf(L" Interface Index[%u]:\t %lu\n", i, i);
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
wprintf(L"StringFromGUID2 failed\n");
else {
wprintf(L" InterfaceGUID[%d]: %ws\n",i, GuidString);
}
wprintf(L" Interface Description[%d]: %ws", i,
pIfInfo->strInterfaceDescription);
wprintf(L"\n");
wprintf(L" Interface State[%d]:\t ", i);
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
wprintf(L"Not ready\n");
break;
case wlan_interface_state_connected:
wprintf(L"Connected\n");
break;
case wlan_interface_state_ad_hoc_network_formed:
wprintf(L"First node in a ad hoc network\n");
break;
case wlan_interface_state_disconnecting:
wprintf(L"Disconnecting\n");
break;
case wlan_interface_state_disconnected:
wprintf(L"Not connected\n");
break;
case wlan_interface_state_associating:
wprintf(L"Attempting to associate with a network\n");
break;
case wlan_interface_state_discovering:
wprintf(L"Auto configuration is discovering settings for the network\n");
break;
case wlan_interface_state_authenticating:
wprintf(L"In process of authenticating\n");
break;
default:
wprintf(L"Unknown state %ld\n", pIfInfo->isState);
break;
}
wprintf(L"\n");
dwResult = WlanGetProfileCustomUserData(hClient,
&pIfInfo->InterfaceGuid,
pProfileName,
NULL,
&dwDataSize,
&pProfileData);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanGetProfileCustomData failed with error: %u\n",
dwResult);
// You can use FormatMessage to find out why the function failed
} else {
wprintf(L"Profile Name: %ws\n", pProfileName);
wprintf(L" dwDataSize:\t 0x%x\n", dwDataSize);
wprintf(L" Profile Custom Data:\n");
// wprintf(L"%ws\n\n", pProfileXml);
wprintf(L"\n");
wprintf(L"\n");
}
}
}
if (pProfileData != NULL) {
WlanFreeMemory(pProfileData);
pProfileData = NULL;
}
if (pIfList != NULL) {
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// wlanapi.dll
#include <windows.h>
DWORD WlanGetProfileCustomUserData(
HANDLE hClientHandle,
const GUID* pInterfaceGuid,
LPCWSTR strProfileName,
void* pReserved, // optional
DWORD* pdwDataSize,
BYTE** ppData
);[DllImport("wlanapi.dll", ExactSpelling = true)]
static extern uint WlanGetProfileCustomUserData(
IntPtr hClientHandle, // HANDLE
ref Guid pInterfaceGuid, // GUID*
[MarshalAs(UnmanagedType.LPWStr)] string strProfileName, // LPCWSTR
IntPtr pReserved, // void* optional
out uint pdwDataSize, // DWORD* out
IntPtr ppData // BYTE** out
);<DllImport("wlanapi.dll", ExactSpelling:=True)>
Public Shared Function WlanGetProfileCustomUserData(
hClientHandle As IntPtr, ' HANDLE
ByRef pInterfaceGuid As Guid, ' GUID*
<MarshalAs(UnmanagedType.LPWStr)> strProfileName As String, ' LPCWSTR
pReserved As IntPtr, ' void* optional
<Out> ByRef pdwDataSize As UInteger, ' DWORD* out
ppData As IntPtr ' BYTE** out
) As UInteger
End Function' hClientHandle : HANDLE
' pInterfaceGuid : GUID*
' strProfileName : LPCWSTR
' pReserved : void* optional
' pdwDataSize : DWORD* out
' ppData : BYTE** out
Declare PtrSafe Function WlanGetProfileCustomUserData Lib "wlanapi" ( _
ByVal hClientHandle As LongPtr, _
ByVal pInterfaceGuid As LongPtr, _
ByVal strProfileName As LongPtr, _
ByVal pReserved As LongPtr, _
ByRef pdwDataSize As Long, _
ByVal ppData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WlanGetProfileCustomUserData = ctypes.windll.wlanapi.WlanGetProfileCustomUserData
WlanGetProfileCustomUserData.restype = wintypes.DWORD
WlanGetProfileCustomUserData.argtypes = [
wintypes.HANDLE, # hClientHandle : HANDLE
ctypes.c_void_p, # pInterfaceGuid : GUID*
wintypes.LPCWSTR, # strProfileName : LPCWSTR
ctypes.POINTER(None), # pReserved : void* optional
ctypes.POINTER(wintypes.DWORD), # pdwDataSize : DWORD* out
ctypes.c_void_p, # ppData : BYTE** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('wlanapi.dll')
WlanGetProfileCustomUserData = Fiddle::Function.new(
lib['WlanGetProfileCustomUserData'],
[
Fiddle::TYPE_VOIDP, # hClientHandle : HANDLE
Fiddle::TYPE_VOIDP, # pInterfaceGuid : GUID*
Fiddle::TYPE_VOIDP, # strProfileName : LPCWSTR
Fiddle::TYPE_VOIDP, # pReserved : void* optional
Fiddle::TYPE_VOIDP, # pdwDataSize : DWORD* out
Fiddle::TYPE_VOIDP, # ppData : BYTE** out
],
-Fiddle::TYPE_INT)#[link(name = "wlanapi")]
extern "system" {
fn WlanGetProfileCustomUserData(
hClientHandle: *mut core::ffi::c_void, // HANDLE
pInterfaceGuid: *const GUID, // GUID*
strProfileName: *const u16, // LPCWSTR
pReserved: *mut (), // void* optional
pdwDataSize: *mut u32, // DWORD* out
ppData: *mut *mut u8 // BYTE** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("wlanapi.dll")]
public static extern uint WlanGetProfileCustomUserData(IntPtr hClientHandle, ref Guid pInterfaceGuid, [MarshalAs(UnmanagedType.LPWStr)] string strProfileName, IntPtr pReserved, out uint pdwDataSize, IntPtr ppData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wlanapi_WlanGetProfileCustomUserData' -Namespace Win32 -PassThru
# $api::WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)#uselib "wlanapi.dll"
#func global WlanGetProfileCustomUserData "WlanGetProfileCustomUserData" sptr, sptr, sptr, sptr, sptr, sptr
; WlanGetProfileCustomUserData hClientHandle, varptr(pInterfaceGuid), strProfileName, pReserved, varptr(pdwDataSize), varptr(ppData) ; 戻り値は stat
; hClientHandle : HANDLE -> "sptr"
; pInterfaceGuid : GUID* -> "sptr"
; strProfileName : LPCWSTR -> "sptr"
; pReserved : void* optional -> "sptr"
; pdwDataSize : DWORD* out -> "sptr"
; ppData : BYTE** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "wlanapi.dll" #cfunc global WlanGetProfileCustomUserData "WlanGetProfileCustomUserData" sptr, var, wstr, sptr, var, var ; res = WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData) ; hClientHandle : HANDLE -> "sptr" ; pInterfaceGuid : GUID* -> "var" ; strProfileName : LPCWSTR -> "wstr" ; pReserved : void* optional -> "sptr" ; pdwDataSize : DWORD* out -> "var" ; ppData : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "wlanapi.dll" #cfunc global WlanGetProfileCustomUserData "WlanGetProfileCustomUserData" sptr, sptr, wstr, sptr, sptr, sptr ; res = WlanGetProfileCustomUserData(hClientHandle, varptr(pInterfaceGuid), strProfileName, pReserved, varptr(pdwDataSize), varptr(ppData)) ; hClientHandle : HANDLE -> "sptr" ; pInterfaceGuid : GUID* -> "sptr" ; strProfileName : LPCWSTR -> "wstr" ; pReserved : void* optional -> "sptr" ; pdwDataSize : DWORD* out -> "sptr" ; ppData : BYTE** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD WlanGetProfileCustomUserData(HANDLE hClientHandle, GUID* pInterfaceGuid, LPCWSTR strProfileName, void* pReserved, DWORD* pdwDataSize, BYTE** ppData) #uselib "wlanapi.dll" #cfunc global WlanGetProfileCustomUserData "WlanGetProfileCustomUserData" intptr, var, wstr, intptr, var, var ; res = WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData) ; hClientHandle : HANDLE -> "intptr" ; pInterfaceGuid : GUID* -> "var" ; strProfileName : LPCWSTR -> "wstr" ; pReserved : void* optional -> "intptr" ; pdwDataSize : DWORD* out -> "var" ; ppData : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD WlanGetProfileCustomUserData(HANDLE hClientHandle, GUID* pInterfaceGuid, LPCWSTR strProfileName, void* pReserved, DWORD* pdwDataSize, BYTE** ppData) #uselib "wlanapi.dll" #cfunc global WlanGetProfileCustomUserData "WlanGetProfileCustomUserData" intptr, intptr, wstr, intptr, intptr, intptr ; res = WlanGetProfileCustomUserData(hClientHandle, varptr(pInterfaceGuid), strProfileName, pReserved, varptr(pdwDataSize), varptr(ppData)) ; hClientHandle : HANDLE -> "intptr" ; pInterfaceGuid : GUID* -> "intptr" ; strProfileName : LPCWSTR -> "wstr" ; pReserved : void* optional -> "intptr" ; pdwDataSize : DWORD* out -> "intptr" ; ppData : BYTE** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wlanapi = windows.NewLazySystemDLL("wlanapi.dll")
procWlanGetProfileCustomUserData = wlanapi.NewProc("WlanGetProfileCustomUserData")
)
// hClientHandle (HANDLE), pInterfaceGuid (GUID*), strProfileName (LPCWSTR), pReserved (void* optional), pdwDataSize (DWORD* out), ppData (BYTE** out)
r1, _, err := procWlanGetProfileCustomUserData.Call(
uintptr(hClientHandle),
uintptr(pInterfaceGuid),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(strProfileName))),
uintptr(pReserved),
uintptr(pdwDataSize),
uintptr(ppData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction WlanGetProfileCustomUserData(
hClientHandle: THandle; // HANDLE
pInterfaceGuid: PGUID; // GUID*
strProfileName: PWideChar; // LPCWSTR
pReserved: Pointer; // void* optional
pdwDataSize: Pointer; // DWORD* out
ppData: Pointer // BYTE** out
): DWORD; stdcall;
external 'wlanapi.dll' name 'WlanGetProfileCustomUserData';result := DllCall("wlanapi\WlanGetProfileCustomUserData"
, "Ptr", hClientHandle ; HANDLE
, "Ptr", pInterfaceGuid ; GUID*
, "WStr", strProfileName ; LPCWSTR
, "Ptr", pReserved ; void* optional
, "Ptr", pdwDataSize ; DWORD* out
, "Ptr", ppData ; BYTE** out
, "UInt") ; return: DWORD●WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData) = DLL("wlanapi.dll", "dword WlanGetProfileCustomUserData(void*, void*, char*, void*, void*, void*)")
# 呼び出し: WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)
# hClientHandle : HANDLE -> "void*"
# pInterfaceGuid : GUID* -> "void*"
# strProfileName : LPCWSTR -> "char*"
# pReserved : void* optional -> "void*"
# pdwDataSize : DWORD* out -> "void*"
# ppData : BYTE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wlanapi" fn WlanGetProfileCustomUserData(
hClientHandle: ?*anyopaque, // HANDLE
pInterfaceGuid: [*c]GUID, // GUID*
strProfileName: [*c]const u16, // LPCWSTR
pReserved: ?*anyopaque, // void* optional
pdwDataSize: [*c]u32, // DWORD* out
ppData: [*c][*c]u8 // BYTE** out
) callconv(std.os.windows.WINAPI) u32;proc WlanGetProfileCustomUserData(
hClientHandle: pointer, # HANDLE
pInterfaceGuid: ptr GUID, # GUID*
strProfileName: WideCString, # LPCWSTR
pReserved: pointer, # void* optional
pdwDataSize: ptr uint32, # DWORD* out
ppData: ptr uint8 # BYTE** out
): uint32 {.importc: "WlanGetProfileCustomUserData", stdcall, dynlib: "wlanapi.dll".}pragma(lib, "wlanapi");
extern(Windows)
uint WlanGetProfileCustomUserData(
void* hClientHandle, // HANDLE
GUID* pInterfaceGuid, // GUID*
const(wchar)* strProfileName, // LPCWSTR
void* pReserved, // void* optional
uint* pdwDataSize, // DWORD* out
ubyte** ppData // BYTE** out
);ccall((:WlanGetProfileCustomUserData, "wlanapi.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{GUID}, Cwstring, Ptr{Cvoid}, Ptr{UInt32}, Ptr{UInt8}),
hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)
# hClientHandle : HANDLE -> Ptr{Cvoid}
# pInterfaceGuid : GUID* -> Ptr{GUID}
# strProfileName : LPCWSTR -> Cwstring
# pReserved : void* optional -> Ptr{Cvoid}
# pdwDataSize : DWORD* out -> Ptr{UInt32}
# ppData : BYTE** out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t WlanGetProfileCustomUserData(
void* hClientHandle,
void* pInterfaceGuid,
const uint16_t* strProfileName,
void* pReserved,
uint32_t* pdwDataSize,
uint8_t** ppData);
]]
local wlanapi = ffi.load("wlanapi")
-- wlanapi.WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)
-- hClientHandle : HANDLE
-- pInterfaceGuid : GUID*
-- strProfileName : LPCWSTR
-- pReserved : void* optional
-- pdwDataSize : DWORD* out
-- ppData : BYTE** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('wlanapi.dll');
const WlanGetProfileCustomUserData = lib.func('__stdcall', 'WlanGetProfileCustomUserData', 'uint32_t', ['void *', 'void *', 'str16', 'void *', 'uint32_t *', 'uint8_t *']);
// WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)
// hClientHandle : HANDLE -> 'void *'
// pInterfaceGuid : GUID* -> 'void *'
// strProfileName : LPCWSTR -> 'str16'
// pReserved : void* optional -> 'void *'
// pdwDataSize : DWORD* out -> 'uint32_t *'
// ppData : BYTE** out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("wlanapi.dll", {
WlanGetProfileCustomUserData: { parameters: ["pointer", "pointer", "buffer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData)
// hClientHandle : HANDLE -> "pointer"
// pInterfaceGuid : GUID* -> "pointer"
// strProfileName : LPCWSTR -> "buffer"
// pReserved : void* optional -> "pointer"
// pdwDataSize : DWORD* out -> "pointer"
// ppData : BYTE** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t WlanGetProfileCustomUserData(
void* hClientHandle,
void* pInterfaceGuid,
const uint16_t* strProfileName,
void* pReserved,
uint32_t* pdwDataSize,
uint8_t** ppData);
C, "wlanapi.dll");
// $ffi->WlanGetProfileCustomUserData(hClientHandle, pInterfaceGuid, strProfileName, pReserved, pdwDataSize, ppData);
// hClientHandle : HANDLE
// pInterfaceGuid : GUID*
// strProfileName : LPCWSTR
// pReserved : void* optional
// pdwDataSize : DWORD* out
// ppData : BYTE** 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 Wlanapi extends StdCallLibrary {
Wlanapi INSTANCE = Native.load("wlanapi", Wlanapi.class);
int WlanGetProfileCustomUserData(
Pointer hClientHandle, // HANDLE
Pointer pInterfaceGuid, // GUID*
WString strProfileName, // LPCWSTR
Pointer pReserved, // void* optional
IntByReference pdwDataSize, // DWORD* out
Pointer ppData // BYTE** out
);
}@[Link("wlanapi")]
lib Libwlanapi
fun WlanGetProfileCustomUserData = WlanGetProfileCustomUserData(
hClientHandle : Void*, # HANDLE
pInterfaceGuid : GUID*, # GUID*
strProfileName : UInt16*, # LPCWSTR
pReserved : Void*, # void* optional
pdwDataSize : UInt32*, # DWORD* out
ppData : UInt8** # BYTE** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WlanGetProfileCustomUserDataNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>);
typedef WlanGetProfileCustomUserDataDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>);
final WlanGetProfileCustomUserData = DynamicLibrary.open('wlanapi.dll')
.lookupFunction<WlanGetProfileCustomUserDataNative, WlanGetProfileCustomUserDataDart>('WlanGetProfileCustomUserData');
// hClientHandle : HANDLE -> Pointer<Void>
// pInterfaceGuid : GUID* -> Pointer<Void>
// strProfileName : LPCWSTR -> Pointer<Utf16>
// pReserved : void* optional -> Pointer<Void>
// pdwDataSize : DWORD* out -> Pointer<Uint32>
// ppData : BYTE** out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WlanGetProfileCustomUserData(
hClientHandle: THandle; // HANDLE
pInterfaceGuid: PGUID; // GUID*
strProfileName: PWideChar; // LPCWSTR
pReserved: Pointer; // void* optional
pdwDataSize: Pointer; // DWORD* out
ppData: Pointer // BYTE** out
): DWORD; stdcall;
external 'wlanapi.dll' name 'WlanGetProfileCustomUserData';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WlanGetProfileCustomUserData"
c_WlanGetProfileCustomUserData :: Ptr () -> Ptr () -> CWString -> Ptr () -> Ptr Word32 -> Ptr Word8 -> IO Word32
-- hClientHandle : HANDLE -> Ptr ()
-- pInterfaceGuid : GUID* -> Ptr ()
-- strProfileName : LPCWSTR -> CWString
-- pReserved : void* optional -> Ptr ()
-- pdwDataSize : DWORD* out -> Ptr Word32
-- ppData : BYTE** out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wlangetprofilecustomuserdata =
foreign "WlanGetProfileCustomUserData"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint8_t) @-> returning uint32_t)
(* hClientHandle : HANDLE -> (ptr void) *)
(* pInterfaceGuid : GUID* -> (ptr void) *)
(* strProfileName : LPCWSTR -> (ptr uint16_t) *)
(* pReserved : void* optional -> (ptr void) *)
(* pdwDataSize : DWORD* out -> (ptr uint32_t) *)
(* ppData : BYTE** out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wlanapi (t "wlanapi.dll"))
(cffi:use-foreign-library wlanapi)
(cffi:defcfun ("WlanGetProfileCustomUserData" wlan-get-profile-custom-user-data :convention :stdcall) :uint32
(h-client-handle :pointer) ; HANDLE
(p-interface-guid :pointer) ; GUID*
(str-profile-name (:string :encoding :utf-16le)) ; LPCWSTR
(p-reserved :pointer) ; void* optional
(pdw-data-size :pointer) ; DWORD* out
(pp-data :pointer)) ; BYTE** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WlanGetProfileCustomUserData = Win32::API::More->new('wlanapi',
'DWORD WlanGetProfileCustomUserData(HANDLE hClientHandle, LPVOID pInterfaceGuid, LPCWSTR strProfileName, LPVOID pReserved, LPVOID pdwDataSize, LPVOID ppData)');
# my $ret = $WlanGetProfileCustomUserData->Call($hClientHandle, $pInterfaceGuid, $strProfileName, $pReserved, $pdwDataSize, $ppData);
# hClientHandle : HANDLE -> HANDLE
# pInterfaceGuid : GUID* -> LPVOID
# strProfileName : LPCWSTR -> LPCWSTR
# pReserved : void* optional -> LPVOID
# pdwDataSize : DWORD* out -> LPVOID
# ppData : BYTE** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f WlanGetProfile — 指定した無線LANプロファイルのXML内容を取得する。
- f WlanGetProfileList — インターフェイスに設定された無線LANプロファイル一覧を取得する。
- f WlanSetProfile — 無線LANプロファイルをXMLから追加または更新する。
- f WlanSetProfileCustomUserData — 無線LANプロファイルにアプリ独自のカスタムデータを設定する。