-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
feat: add IsWindows8OrGreater()
and GetCurrentPackageFullName()
APIs
#943
Comments
I was trying this myself, and ran into an issue. |
You need to implement inline functions yourself, you can't wrap them with FFI. See win32/packages/win32/lib/src/inline.dart Line 103 in 249459b
Here's the implementation of the const _WIN32_WINNT_WIN8 = 0x0602;
/// Indicates if the current OS version matches, or is greater than, the
/// Windows 8 version.
///
/// {@category version}
int IsWindows8OrGreater() => IsWindowsVersionOrGreater(
HIBYTE(_WIN32_WINNT_WIN8),
LOBYTE(_WIN32_WINNT_WIN8),
0,
); And final _kernel32 = DynamicLibrary.open('kernel32.dll');
/// Gets the package full name for the calling process.
///
/// ```c
/// LONG GetCurrentPackageFullName(
/// UINT32 *packageFullNameLength,
/// PWSTR packageFullName
/// );
/// ```
/// {@category kernel32}
int GetCurrentPackageFullName(Pointer<Uint32> packageFullNameLength,
Pointer<Utf16> packageFullName) =>
_GetCurrentPackageFullName(packageFullNameLength, packageFullName);
final _GetCurrentPackageFullName = _kernel32.lookupFunction<
Uint32 Function(
Pointer<Uint32> packageFullNameLength, Pointer<Utf16> packageFullName),
int Function(Pointer<Uint32> packageFullNameLength,
Pointer<Utf16> packageFullName)>('GetCurrentPackageFullName'); I'll probably add these to the package tomorrow. I didn't test it but this should work: import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
bool checkIdentity() {
if (IsWindows8OrGreater() == FALSE) return false;
final length = calloc<Uint32>();
try {
var error = GetCurrentPackageFullName(length, nullptr);
if (error == WIN32_ERROR.APPMODEL_ERROR_NO_PACKAGE) {
return false;
} else if (error != WIN32_ERROR.ERROR_INSUFFICIENT_BUFFER) {
return false;
}
final packageFullName = wsalloc(length.value);
error = GetCurrentPackageFullName(length, packageFullName);
free(packageFullName);
return error == WIN32_ERROR.ERROR_SUCCESS;
} finally {
free(length);
}
}
void main() {
if (checkIdentity()) {
print('This is a Windows 8+ Store App');
} else {
print('This is not a Windows 8+ Store App');
}
} |
Thanks again! |
I have a concrete use-case at YehudaKremer/msix#292: Determining if your app is running with package identity:
Seems this package doesn't include
<appmodel.h>
, so I can't useIsWindows8OrGreater()
orGetCurrentPackageFullName()
.Originally posted by @Levi-Lesches in #819 (comment)
The text was updated successfully, but these errors were encountered: