call Win32 API in flex to set Window Display Affinity
Asked Answered
C

1

7

I have created a Flex Desktop Application with Adobe Air. I need to protect the application from being captured. By changing the window display affinity of the application, the application can be protected from being captured. How to use win API in flex? Is there any other way to protect the window from being captured?

Carafe answered 9/6, 2015 at 5:21 Comment(12)
Do you mind if my answer says you have to build a C DLL, as an "Air Extension" (for Air 3)?Henbit
If you call the setwindowdisplayaffinity from other process, it returns ACCESS DENIED. Then it will be of no use.Carafe
The Dll would be an AIR extension, running in the application process. No "access denied" here.Henbit
Actually I am using flerry as java bridge between Java and Flex. Although the code in java is from the same process it is giving "ACCESS DENIED" error. I am finding the window using FindWindow(null,title) to get the HWND of the application, then changing the window display affinity. Is there any direct way to get HWND of the application running? BTW if possible share the example link for building C DLL as an Air ExtensionCarafe
I don't understand. Why do you want the HWND? The API failing with "access denied" is FindWindow or SetWindowDisplayAffinity? You should update your question. Link for AIR Extension: adobe.com/content/dam/Adobe/en/devnet/devices/pdfs/…Henbit
It is with SetWindowDisplayAffinity.Carafe
The error ACCESS_DENIED for SetWindowDisplayAffinity typically means you issue the call for an HWND which is NOT in you process. Double check, with debugging tools and spies, the HWND value and the process issuing the call.Henbit
I made a simple C++ DLL, injected in process via SetWindowsHookEx. Works OK for notepad.exe (print screen gives "all black" Client Area). Injected in an AIR Desktop application, I get NOT_ENOUGH_MEMORY for SetWindowDisplayAffinity... I don't know why.Henbit
OK. I managed to make SetWindowDisplayAffinity works for an Air Desktop Application: The main Window must NOT been made "transparent" in the -app.xml file (that is: no WS_EX_LAYERED Windows styles seen by Spy++) Print Screen now gives me "all black" image.Henbit
Many thanks. Do not hesitate to ask for some details, if you need them.Henbit
Sure. Will send you a ZIP in the coming days. Email copy/pasted, you can delete your comment.Henbit
ZIP sent. Sorry for delay.Henbit
H
2

First you have to make sure that the main window does not have the WS_EX_LAYERED Windows style. That style makes SetWindowDisplayAffinity fails with code 8 (ERROR_NOT_ENOUGH_MEMORY), at least on my machine (Seven Pro 64 bits). In your -app.xml file, set the value to false for the node <transparent> under <initialWindow>.

Second, you have to choose how to inject a regular C DLL in the application process, as the API will fail with error 5 (ERROR_ACCESS_DENIED) if you try to change the affinity of a window not living in the caller process.

One possible injection method is using the SetWindowsHookEx API. Google will give you many hits about that one. Feel free to ask for some details. You obviously needs cooperation of another process, here (and some Win32 APIs practice).

Another possible way is coding an 'ACTIONSCRIPT® Extensions for ADOBE® AIR®' (PDF).

The later seems preferable:

  • No collaboration from an external process needed.
  • Adobe AIR does the DLL loading for you.
  • C/C++ code much more simple.

I used the first technique, as I am more fluent in raw Win32 APIs about DLL, than I am with AIR and Action Script...

I successfully tested that first technique with a very simple "Hello World" AIR Desktop application, and get a nice "All Black" image after Print Screen.

Henbit answered 18/6, 2015 at 11:48 Comment(1)
It also doesn't work if you set AllowsTransparency to true in a WPF window.Prindle

© 2022 - 2024 — McMap. All rights reserved.