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

WinUI3 Sample #41

Open
F1schk0pp opened this issue Apr 12, 2023 · 7 comments
Open

WinUI3 Sample #41

F1schk0pp opened this issue Apr 12, 2023 · 7 comments

Comments

@F1schk0pp
Copy link

Hi @soukoku,

could you try to provide a WinUi3 sample?
I would code it by myself but i currently have no working scanner available.

I have tried it in the past with v3 but it was not working.
Maybe it is possible in v4?

@soukoku
Copy link
Owner

soukoku commented Apr 13, 2023

It essentially needs to be able to get into the UI message loop to intercept messages and pass some of them to TWAIN. This does not seem possible when I investigated before. There's no extensibility point at that level like winform/wpf does.

If that's still true, one choice is to run your own message pump in another thread. Unfortunately I'm probably not experienced enough in win32 to make one correctly (maybe I can try in the future). Another option is to run a separate process based on winform/wpf that the main app talks to through some IPC mechanism. That's what I was trying to do with the signalr test :p

@F1schk0pp
Copy link
Author

F1schk0pp commented Apr 13, 2023

I managed to hook into the message loop in a WinUi3 application with this code:
https://www.michaelwda.com/post/netcore_message_pump

But instead of WinMsg I used your WIN_MESSAGE.

But I don't know how to implement it in NTwain.

Maybe you will have more luck if you want to try it. You are probably more experienced than me. 😅

@soukoku
Copy link
Owner

soukoku commented Apr 14, 2023

While I appear to have a working self-hosted loop using winform that works in other places (like avalon ui), WinUI3 apps just don't seem to work with twain in general.

Showing the old select dialog and opening a source doesn't require hooking into the mesage loop and even those don't work right. I suspect the dynamic loading nature of sources are restricted or something though I have no proof. Your only option may be a separate exe process that you control through some IPC.

@F1schk0pp
Copy link
Author

Ah ok i see..
Hmh, maybe i will try it with IPC and a extra "worker" app 🤔

If i succeed, i will create a PR with a WinUi3 sample 👍

@christopher-carmichael
Copy link

christopher-carmichael commented Apr 27, 2023

So I thought I would chime in here, basically you have two options. If you select your winui3 app to run unpackaged it will natively have access to win32 apis. This should allow ntwain to work. But a key new feature in Winui3 vs UWP is allowing fulltrust applications within the app package. So if you open package manifest and set uap10:TrustLevel attribute in and I believe add the following capabilities are necessary, but it has been months since I initially set up so a little foggy:

<Applications>
<Application
uap10:TrustLevel="mediumIL"
....
...
...>

<Capabilities>
		<rescap:Capability Name="runFullTrust"/>
		<rescap:Capability Name="unvirtualizedResources"/>
	</Capabilities>

I am successfully using Ntwain in this capacity in a WinUi3 application. This is actually a great improvement because before we were using a UWP app and had to have an IPC to a win32 app that did the scanning and pass back scan.

@F1schk0pp
Copy link
Author

Thx, if i run it unpackaged it works.
v4 however throws a NotSupportedException when calling EnableSource:
The send method is not supported, use Post instead.

@F1schk0pp
Copy link
Author

I have managed to get it work with WinUi3.
I will submit a PR the next days.

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