Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is InitPropVariantFromString? #1946

Closed
AArnott opened this issue Jul 15, 2024 · 4 comments
Closed

Where is InitPropVariantFromString? #1946

AArnott opened this issue Jul 15, 2024 · 4 comments

Comments

@AArnott
Copy link
Member

AArnott commented Jul 15, 2024

Discussed in microsoft/CsWin32#1234

Originally posted by optsing July 10, 2024
If I add InitPropVariantFromString to NativeMethods.txt, I get the warning message

Method, type or constant "InitPropVariantFromString" not found. Did you mean or "InitPropVariantFromStringVector" or "InitPropVariantFromStringAsVector"?

Why is this method missing? What is the correct way to create PROPVARIANT without it?

It's missing from the metadata, but it is a documented function.

@ChrisDenton
Copy link
Contributor

From the "Requirements" section of the documentation page, it looks like it's a header-only function. So it's not actually exposed by any Windows DLLs.

@ChrisDenton
Copy link
Contributor

If I look at the mentioned propvarutil.h I see:

// Creates a VT_LPWSTR propvariant.
inline HRESULT InitPropVariantFromString(_In_ PCWSTR psz, _Out_ PROPVARIANT *ppropvar)
{
HRESULT hr = psz != nullptr ? S_OK : E_INVALIDARG; // Previous API behavior counter to the SAL requirement.
if (SUCCEEDED(hr))
{
SIZE_T const byteCount = static_cast<SIZE_T>((wcslen(psz) + 1) * sizeof(*psz));
V_UNION(ppropvar, pwszVal) = static_cast<PWSTR>(CoTaskMemAlloc(byteCount));
hr = V_UNION(ppropvar, pwszVal) ? S_OK : E_OUTOFMEMORY;
if (SUCCEEDED(hr))
{
memcpy_s(V_UNION(ppropvar, pwszVal), byteCount, psz, byteCount);
V_VT(ppropvar) = VT_LPWSTR;
}
}
if (FAILED(hr))
{
PropVariantInit(ppropvar);
}
return hr;
}

@AArnott
Copy link
Member Author

AArnott commented Jul 15, 2024

Interesting observation about being an inline function. I suspect that's why the clang scanner missed it. The metadata doesn't expect to include macros most of the time, but I don't know about these inline functions.

@riverar
Copy link
Collaborator

riverar commented Jul 15, 2024

InitPropVariantFromString is a header-only helper function. It's not available for use outside of C++.

@riverar riverar closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants