SHCLSIDFromString
関数文字列をCLSID(GUID)に変換する。
シグネチャ
// SHELL32.dll
#include <windows.h>
HRESULT SHCLSIDFromString(
LPCWSTR psz,
GUID* pclsid
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| psz | LPCWSTR | in | {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} の形式で CLSID を含む Unicode 文字列です。 |
| pclsid | GUID* | out | CLSID 値へのポインターです。この関数が正常に終了すると、変換された文字列が CLSID として格納されます。 |
戻り値の型: HRESULT
公式ドキュメント
クラス識別子 (CLSID) の文字列形式を受け取り、対応する CLSID を生成します。
戻り値
型: HRESULT
この関数が成功すると S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
HRESULT SHCLSIDFromString(
LPCWSTR psz,
GUID* pclsid
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHCLSIDFromString(
[MarshalAs(UnmanagedType.LPWStr)] string psz, // LPCWSTR
out Guid pclsid // GUID* out
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHCLSIDFromString(
<MarshalAs(UnmanagedType.LPWStr)> psz As String, ' LPCWSTR
<Out> ByRef pclsid As Guid ' GUID* out
) As Integer
End Function' psz : LPCWSTR
' pclsid : GUID* out
Declare PtrSafe Function SHCLSIDFromString Lib "shell32" ( _
ByVal psz As LongPtr, _
ByVal pclsid As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHCLSIDFromString = ctypes.windll.shell32.SHCLSIDFromString
SHCLSIDFromString.restype = ctypes.c_int
SHCLSIDFromString.argtypes = [
wintypes.LPCWSTR, # psz : LPCWSTR
ctypes.c_void_p, # pclsid : GUID* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHCLSIDFromString = Fiddle::Function.new(
lib['SHCLSIDFromString'],
[
Fiddle::TYPE_VOIDP, # psz : LPCWSTR
Fiddle::TYPE_VOIDP, # pclsid : GUID* out
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHCLSIDFromString(
psz: *const u16, // LPCWSTR
pclsid: *mut GUID // GUID* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHCLSIDFromString([MarshalAs(UnmanagedType.LPWStr)] string psz, out Guid pclsid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHCLSIDFromString' -Namespace Win32 -PassThru
# $api::SHCLSIDFromString(psz, pclsid)#uselib "SHELL32.dll"
#func global SHCLSIDFromString "SHCLSIDFromString" sptr, sptr
; SHCLSIDFromString psz, varptr(pclsid) ; 戻り値は stat
; psz : LPCWSTR -> "sptr"
; pclsid : GUID* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHCLSIDFromString "SHCLSIDFromString" wstr, var ; res = SHCLSIDFromString(psz, pclsid) ; psz : LPCWSTR -> "wstr" ; pclsid : GUID* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHCLSIDFromString "SHCLSIDFromString" wstr, sptr ; res = SHCLSIDFromString(psz, varptr(pclsid)) ; psz : LPCWSTR -> "wstr" ; pclsid : GUID* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SHCLSIDFromString(LPCWSTR psz, GUID* pclsid) #uselib "SHELL32.dll" #cfunc global SHCLSIDFromString "SHCLSIDFromString" wstr, var ; res = SHCLSIDFromString(psz, pclsid) ; psz : LPCWSTR -> "wstr" ; pclsid : GUID* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHCLSIDFromString(LPCWSTR psz, GUID* pclsid) #uselib "SHELL32.dll" #cfunc global SHCLSIDFromString "SHCLSIDFromString" wstr, intptr ; res = SHCLSIDFromString(psz, varptr(pclsid)) ; psz : LPCWSTR -> "wstr" ; pclsid : GUID* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHCLSIDFromString = shell32.NewProc("SHCLSIDFromString")
)
// psz (LPCWSTR), pclsid (GUID* out)
r1, _, err := procSHCLSIDFromString.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz))),
uintptr(pclsid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHCLSIDFromString(
psz: PWideChar; // LPCWSTR
pclsid: PGUID // GUID* out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHCLSIDFromString';result := DllCall("SHELL32\SHCLSIDFromString"
, "WStr", psz ; LPCWSTR
, "Ptr", pclsid ; GUID* out
, "Int") ; return: HRESULT●SHCLSIDFromString(psz, pclsid) = DLL("SHELL32.dll", "int SHCLSIDFromString(char*, void*)")
# 呼び出し: SHCLSIDFromString(psz, pclsid)
# psz : LPCWSTR -> "char*"
# pclsid : GUID* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn SHCLSIDFromString(
psz: [*c]const u16, // LPCWSTR
pclsid: [*c]GUID // GUID* out
) callconv(std.os.windows.WINAPI) i32;proc SHCLSIDFromString(
psz: WideCString, # LPCWSTR
pclsid: ptr GUID # GUID* out
): int32 {.importc: "SHCLSIDFromString", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int SHCLSIDFromString(
const(wchar)* psz, // LPCWSTR
GUID* pclsid // GUID* out
);ccall((:SHCLSIDFromString, "SHELL32.dll"), stdcall, Int32,
(Cwstring, Ptr{GUID}),
psz, pclsid)
# psz : LPCWSTR -> Cwstring
# pclsid : GUID* out -> Ptr{GUID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHCLSIDFromString(
const uint16_t* psz,
void* pclsid);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHCLSIDFromString(psz, pclsid)
-- psz : LPCWSTR
-- pclsid : GUID* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHCLSIDFromString = lib.func('__stdcall', 'SHCLSIDFromString', 'int32_t', ['str16', 'void *']);
// SHCLSIDFromString(psz, pclsid)
// psz : LPCWSTR -> 'str16'
// pclsid : GUID* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHCLSIDFromString: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.SHCLSIDFromString(psz, pclsid)
// psz : LPCWSTR -> "buffer"
// pclsid : GUID* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHCLSIDFromString(
const uint16_t* psz,
void* pclsid);
C, "SHELL32.dll");
// $ffi->SHCLSIDFromString(psz, pclsid);
// psz : LPCWSTR
// pclsid : GUID* 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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
int SHCLSIDFromString(
WString psz, // LPCWSTR
Pointer pclsid // GUID* out
);
}@[Link("shell32")]
lib LibSHELL32
fun SHCLSIDFromString = SHCLSIDFromString(
psz : UInt16*, # LPCWSTR
pclsid : GUID* # GUID* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHCLSIDFromStringNative = Int32 Function(Pointer<Utf16>, Pointer<Void>);
typedef SHCLSIDFromStringDart = int Function(Pointer<Utf16>, Pointer<Void>);
final SHCLSIDFromString = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHCLSIDFromStringNative, SHCLSIDFromStringDart>('SHCLSIDFromString');
// psz : LPCWSTR -> Pointer<Utf16>
// pclsid : GUID* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHCLSIDFromString(
psz: PWideChar; // LPCWSTR
pclsid: PGUID // GUID* out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHCLSIDFromString';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHCLSIDFromString"
c_SHCLSIDFromString :: CWString -> Ptr () -> IO Int32
-- psz : LPCWSTR -> CWString
-- pclsid : GUID* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shclsidfromstring =
foreign "SHCLSIDFromString"
((ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* psz : LPCWSTR -> (ptr uint16_t) *)
(* pclsid : GUID* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHCLSIDFromString" shclsidfrom-string :convention :stdcall) :int32
(psz (:string :encoding :utf-16le)) ; LPCWSTR
(pclsid :pointer)) ; GUID* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHCLSIDFromString = Win32::API::More->new('SHELL32',
'int SHCLSIDFromString(LPCWSTR psz, LPVOID pclsid)');
# my $ret = $SHCLSIDFromString->Call($psz, $pclsid);
# psz : LPCWSTR -> LPCWSTR
# pclsid : GUID* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。