简体   繁体   中英

Calling windows UWP API's from Java with JNA

How can I call a windows UWP API from the JVM?
For example the Windows.Security.Credentials API.
When attempting to use JNA none of the native library names I have tried will link, and I can't actually find a DLL that matches the name Windows.Security.Credentials.dll as described in the documentation.

Is what I want to do even possible, how can I link to and call UWP API's?

Update: I completely missed the mark on my first answer, was thinking JNI, not JNA, which looks a bit more like C# pInvoke. The code below is roughly what you'll need, but you'll need to reconstruct the v-tables for IInspectable and IPasswordVault. You can use the activation factory instead of activating the instance through RoActivateInstance, but then you'll need to reconstruct the interface for IActivationFactory as well. Otherwise the call suquence below is correct, if in the wrong language.

You can link and call against RoActivateInstance or RoGetActivationFactory and use the low-level COM-styl ABI interfaces defined the SDK in Windows.Security.Credentials.h. Same import lib as above.

eg:

IInspectable *pI {};
Windows::Security::Credentials::IPasswordVault pPV;
HRESULT hr = RoActivateInstance(L"Windows.Security.Credentials.PasswordVault", &pI);
if (SUCCEEDED(hr)) {
  hr = pI->QueryInterface(__uuidof(Windows::Security::Credentials::IPasswordVault), (void**)&pPV);
}
if (SUCCEEDED(hr)) {
  IVectorView<IPasswordCredential> *pPV{}; // namespaces omitted
  hr = pPV->RetrieveAll(&pPV);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM