How to access Windows.Devices.Scanners from WPF - c#

I need to acquire images from a scanner in my WPF application. I've used the open source TwainDotNet Twain32 wrapper, however, there are some Windows 8.1 devices that throw an AccessViolationException. I would like to use the latest Microsoft supported WIA wrappers in the Windows.Devices.Scanners namespace rather than buy a product to enable scanning on Windows 8.1+ machines.
I've successfully been able to use some of the Windows.Devices.* types for video recording in a WPF app via the following instructions: How to use specific WinRT API from Desktop apps: capturing a photo using your webcam into a WPF app
When you look at the documentation for Windows.Devices.Scanners ImageScanner class, You can see that the minimum supported client is Windows 8.1 [Windows Store apps, desktop apps]. Since it is available to both Windows Store Apps and Desktop apps, this means that you should be able to use this namespace and the associated classes from within WPF. The metadata is listed as Windows.winmd which I believe is already referenced in the project (A reference to Windows) as outlined in the tutorial above.
My question: How can I use the Windows.Devices.Scanners types in a WPF application running on Windows 8.x+ ?
Thanks in advance to all replies

The documentation states that the minimum supported client is Windows 8.1. The tutorial that you used told you to edit the CSPROJ file to add the following code:
<TargetPlatformVersion>8.0</TargetPlatformVersion>
Change this to 8.1 in order to reference 8.1 only types:
<TargetPlatformVersion>8.1</TargetPlatformVersion>

Related

Access a HID that does not define the usage page: possible within UWP?

My question. I have a basic HID that does not define any Usage Page and I need to communicate with it from a UWP application. Something really simple: I just need to write/read few bytes from an eeprom integrated in the HID. Can it be done?
What I have done so far. I looked for the following solutions:
Plan A. Write a UWP code to access the device. The Windows.Devices.HumanInterfaceDevice namespace allows UWP applications to access HIDs. However there are limitations... among these, the device is required to define a Usage Page within the vendor range 0xFF00-0xFFFF. So I soon realized this probably cannot work and I expect to run in to a HID_USAGE_PAGE_UNDEFINED problem.
https://learn.microsoft.com/en-us/previous-versions/windows/apps/dn263140(v=win.10)
Plan B. I already have some code that works with this device on Windows 10, but it comes from a WPF application and it is based on hid.dll. It looks like I cannot just integrate this kind of code in a UWP application:
Can I Use Windows Hid API Calls in UWP (HidD_GetPreparsedData)?
Any workaround? suggestion?... is it just plain impossible? I am bound to using UWP.
I ran across this before with UWP. If you are using UWP for an IOT device, this may not work you would need an enterprise version of the IOT device, reason being is you could integrate your HUB dll with a .netframework service running in the background and use signal R to relay your package from your service running in the background to your UWP project.

What are the differences between Windows Desktop C# Apps and just apps?

Here are two similar articles:
1) https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast
2) https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop
I can't get info one thing. First article provides tutorial for notifications for apps. Another article shows tutorial for Desktop C# app. What to choose and what are the differences? Thanks.
When they call them apps like what they mean that are the apps made with the new technology called UWP (Universal Windows Platform) which only work with Windows 10. You can see it here.
Prerequisites
To fully understand this topic, the following will be helpful...
A working knowledge of toast notification terms and concepts. For more information, see Toast and action center overview.
A familiarity with Windows 10 toast notification content. For more information, see toast content documentation.
A Windows 10 UWP app project
Then what they call Desktop C# app, are the "classic" ways to do windows applications. For example WPF (Windows Presentation Foundation) in C# which runs in most Windows machines, like Windows 7 or Vista, also they meant the application made in c++.
The main difference is that what they call apps are the ones made with UWP, these ones work well on windows tables, windows phones, and so on.
And desktop c# app
is an app created with WPF which is a little older but works in older OS's.

Using Universal Windows Platform (Windows 10) controls in WPF

Hopefully a simple question; I seem to recall seeing somebody at one of the recent Microsoft conferences say that some of the UWP application functionality was to be made available within WPF/Desktop. Unfortunately, I can no longer find (or remember) which of the many videos this was from (though it was probably Build or similar on Channel9).
Is it therefore possible to use UWP controls within a WPF application? Basically I want the look and feel of an "app", including some of the new controls (RelativePanel, SplitPanel) and the themed buttons etc., but I need the power of the full desktop - such as access to the full file system.
Thanks.
I think you are referring to the different Bridges to port apps to Windows 10 from for instance, IOS, Android, Web, Win32, etc. and still take advantage of Windows 10 features and APIs. Specifically, I think you are talking about the Bridge to bring in Win32 apps. You can find the bridges listed here.
https://dev.windows.com/en-us/bridges
•"Project Centennial": This toolkit will enable desktop developers to package and publish their existing .NET and Win32-based Windows applications to the Windows Store. Developers can also use Centennial to call common UWP APIs and services."

Windows Store 8.1 and System.Windows.Forms

Recently, I tried to make a battery app (C#, store app) for Windows 8.1
(I am using VS2013, tried also VS2012 with the same result).
As it turned out, I need to add a Reference to the project - but I cannot add anything in Reference Manager: it says "All of the Framework assemblies are already referenced". And all what I need is to get System.Windows.Forms - when I search for it, nothing appears.
Any ideas, what can I do?
(Please tell me if I forgot something essential)
Windows Store Apps are build, from scratch, on new technology stack , So Windows Form and WPF are not part of Windows Store apps.
Windows store apps and Windows Forms apps has there different set of
APIs.
Windows store apps are used to known as known as Metro apps and Right now they have been merging the stuff(don't want to go into the details).
This will give a basic knowledge about this new Technology
So, above are the just a small hints about the differences. Actually, It is not possible to explain all the stuff here. Just explore.

Proximity tap in WPF

I'm trying to detect nearby devices using NFC or RFID from within a WPF application.
Microsoft's proximity API seems to be the right way to go:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465221.aspx
Unfortunately, I see no way to get it running inside a WPF application (or any other Desktop Technology that is). All examples refer to Microsoft store apps only.
From within a WPF application I cannot reference the Namespace
using Windows.Networking.Proximity;
Is it just a reference that I am missing? Is it possible to use the proximity API from a WPF application at all?
I finally found a sample project using the proximity API from within a WPF application:
http://code.msdn.microsoft.com/windowsdesktop/NFC-Editor-529ccda6
There is also a short tutorial included on how to use WinRT API's in WPF applications.
The basic steps:
Manually add a <TargetPlatformVersion>8.0</TargetPlatformVersion> line to the csproj file
Back in Visual Studio, add a reference to Windows/Core/Windows to the project references
Add a reference to the Windows Runtime assemblies to the project.
See above given link for details.
I believe that the Windows.Networking.Proximity.ProximityDevice class is not available in WPF Applications. If you look on the ProximityDevice class page on MSDN, you'll see that it is part of the Windows.Phone API:
The monitor image next to the phone image also leads me to believe that it is available for Windows Store Apps too. I'm guessing that (at present at least) the vast majority of desktop computers won't have any RFC hardware that could be used with this code and so that is why it is missing from the standard .NET dlls.
[2020 is here]
Procedure to prepare your Console/WPF project to call UWP APIs (both are OK):
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance
https://blogs.windows.com/windowsdeveloper/2019/09/30/windows-10-winrt-api-packs-released/
Heads up: You'll need to migrate the project from the packages.config management format to the PackageReference format
https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference#migration-steps

Categories