问题
My question is simple.
How can I call a WinAPI Method like emptyClipboard in an UWP app?
I included the 'Windows Desktop Extensions for the UWP'
The method is listed under Windows API Index / Data Exchange / Clipboard Reference / Clipboard Functions
I've tried the following (js
):
Windows.emptyClipboard();
Windows.WinAPI.emptyClipboard();
Windows.ApplicationModel.emptyClipboard();
Windows.DataExchange.emptyClipboard();
Windows.DataExchange.Clipboard.emptyClipboard();
each of them giving me the following error (as expected):
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'emptyClipboard'
回答1:
You cannot call WinAPI functions directly from a Universal Windows application. You have to find the equivalent function in the Windows Runtime (WinRT).
To clear the Clipboard, use the follwing code:
Windows.ApplicationModel.DataTransfer.Clipboard.clear();
When you edit your UWP application project and add a reference to "Windows Desktop Extensions for the UWP", you do not allow the app to call WinAPI functions directly, but you enable using a part of the Windows Runtime (WinRT) that only makes sense on desktop computers.
Here is a list of WinRT functionality that is only available when you reference "Windows Desktop Extensions for the UWP"
来源:https://stackoverflow.com/questions/42444651/uwp-how-to-call-winapi-method