halildurmus / win32

Access common Win32 APIs directly from Dart using FFI — no C required!
https://win32.pub
BSD 3-Clause "New" or "Revised" License
760 stars 123 forks source link

feat: Add propvarutil.h support #889

Closed FadyQJ closed 1 month ago

FadyQJ commented 1 month ago

Use case

I tried manually writing the missing code but I am not an expert on this

Proposal

I am looking to use IsPropVariantString and PropVariantToStrRet but they are not available in the package

halildurmus commented 1 month ago

I don't plan on adding these APIs to the package anytime soon, but you can call these APIs as follows:

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

final _propsys = DynamicLibrary.open('propsys.dll');

/// Specifies whether a specified PROPVARIANT structure is a string type.
///
/// To learn more, see
/// <https://learn.microsoft.com/windows/win32/api/propvarutil/nf-propvarutil-ispropvariantstring>.
int IsPropVariantString(Pointer<PROPVARIANT> propvar) =>
    PropVariantToStringWithDefault(propvar, nullptr) != nullptr ? TRUE : FALSE;

/// Extracts a string from a PROPVARIANT structure and places it into a STRRET
/// structure.
///
/// To learn more, see
/// <https://learn.microsoft.com/windows/win32/api/propvarutil/nf-propvarutil-propvarianttostrret>.
int PropVariantToStrRet(
        Pointer<PROPVARIANT> propvar, Pointer<STRRET> pstrret) =>
    _PropVariantToStrRet(propvar, pstrret);

final _PropVariantToStrRet = _propsys.lookupFunction<
    HRESULT Function(Pointer<PROPVARIANT>, Pointer<STRRET>),
    int Function(Pointer<PROPVARIANT>, Pointer<STRRET>)>('PropVariantToStrRet');

/// Extracts the string property value of a PROPVARIANT structure.
///
/// If no value exists, then the specified default value is returned.
///
/// To learn more, see
/// <https://learn.microsoft.com/windows/win32/api/propvarutil/nf-propvarutil-propvarianttostringwithdefault>.
Pointer<Utf16> PropVariantToStringWithDefault(
        Pointer<PROPVARIANT> propvarIn, Pointer<Utf16> pszDefault) =>
    _PropVariantToStringWithDefault(propvarIn, pszDefault);

final _PropVariantToStringWithDefault = _propsys.lookupFunction<
    Pointer<Utf16> Function(Pointer<PROPVARIANT>, Pointer<Utf16>),
    Pointer<Utf16> Function(Pointer<PROPVARIANT>,
        Pointer<Utf16>)>('PropVariantToStringWithDefault');
FadyQJ commented 1 month ago

Thanks! I could not find the dll in question.

I am adding features to set / get default audio devices and volume based on this https://github.com/Far-Se/win32audio/blob/master/windows/win32audio_plugin.cpp Hence why I need it.

Just mentioning it in case it helps

Anyway thanks!

github-actions[bot] commented 8 hours ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including a minimal reproduction of the issue.