microsoft / Windows.UI.Composition-Win32-Samples

Windows.UI.Composition Win32 Samples
MIT License
459 stars 186 forks source link

Example cpp/ScreenCaptureforHWND not working - Unhandled exception at 0x00007FFD3B8B9129 (KernelBase.dll) in ScreenCaptureforHWND.exe #37

Closed gileli121 closed 5 years ago

gileli121 commented 5 years ago

Hello, I tried to run the example ScreenCaptureforHWND

Using Visual Studio 2019 on Windows 10 64bit with SDK 10.0.18362.0

The example app was successfully built and working until I select some window to capture.

When I select a window, it always throws an exception image

Unhandled exception at 0x00007FFD3B8B9129 (KernelBase.dll) in ScreenCaptureforHWND.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

It is no matter what window I select. It always fails in this like.

Please fix the example.

Thank you.

robmikh commented 5 years ago

It seems that you're failing the QI to get the IGraphicsCaptureItemInterop interface. Which version of Windows are you running? This feature was added in the 1903 update.

gileli121 commented 5 years ago

I have OS Build 10.0.17763.557 I will try it again after updating and will let you know if the issue resolved

gileli121 commented 5 years ago

Hello, after I updated the example works. Good. is there an otption to not capture the mouse pointer?

And now I have another issue with the API function DwmRegisterThumbnail from here: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmregisterthumbnail

My program makes some big use with this function and after this update the function is not working as expected. Please see the issue I reported to Microsoft:

https://answers.microsoft.com/en-us/windows/forum/windows_10-update/dwmregisterthumbnail-is-not-working-as-expected-in/72dcf82e-7e8e-46f6-b7f3-d80f6f34fefa?tm=1562540172919

I know that the issue is not related to this. I just don't know where to get the support. Please let me know where to get support about this issue. I am not sure that I reported it in the right place.

The issue is big and it broke something in my program... Please help me to get support about this.

Thanks

robmikh commented 5 years ago

Glad to hear the sample is working. The current Insider builds have an API we plan to add that makes the cursor rendering configurable. Look for a new property on GraphicsCaptureSession named IsCursorCaptureEnabled.

As for your issue with DwmRegisterThumbnail, what exactly are you having a problem with? Multiple thumbnails that are assigned to a single window, or the same thumbnail (or at least thumbnails targeting the same window) across multiple windows? I tried both just now and couldn't reproduce any issues. What would I do to reproduce this?

gileli121 commented 5 years ago

Hello, I think that the problem is when you use the API via DLL file.. I could reproduce the bug only by using the API from a script that written in Autoit.

Please try to run this code: https://pastebin.com/MNABim8w

Note that you will need to update the target window to display a preview for in line: $targetGUI = HWnd(0x000000000002004C)

The problem is that you will see only one window getting the live preview. it did not happned before the update.

This is how it looks: image

The preview 2 window don't get a live preview. Only the first one. If I will remove this line that create the first preview: $handle1 = RegisterWindowLivePreview($targetGUI,$hGUI1)

The second preview will work.

I think that the problem is because the API returns the same HTHUMBNAIL twice. The this line: $aRet = DllCall("dwmapi.dll", "int", "DwmRegisterThumbnail", "hwnd", $hwnd, "hwnd", $hWndOw, "ptr*", DllStructGetPtr($tID)) Will call to this function. the function returns the ID 1 even the second time. I think that this is the bug.. But in C++ version I did not saw this. The ID was 2 on the second call and not 1.

gileli121 commented 5 years ago

It seems that you did some change in dwmapi.dll in this update. It seems that this dll now stores some global memory for the HTHUMBNAIL ID.

I know this because I found the solution. The solution is open the dll file using: $dwmDll = DllOpen('dwmapi.dll')

And then in any line that calls the dll, I need to use the dll handle $dwmDll So instead of DllCall('dwmapi.dll', ... I write DllCall($dwmDll, ...

This was solved the issue and now the script print different HTHUMBNAIL on the second call as expected.

robmikh commented 5 years ago

That seems like there was a behavior change in Autoit, I can't get this to happen in C++. Glad everything was sorted out for you.

krenner commented 5 years ago

Hi gileli121 - I wanted to comment on your question re: mouse cursors. Insider preview builds 18894 or greater have a new property on GraphicsCaptureSession named IsCursorCaptureEnabled. Release notes are here.

gileli121 commented 5 years ago

Thanks. Will be also an option to remove the yellow frame of the window that under capture mode?

robotogre commented 3 years ago

@robmikh I am seeing this error in the latest version of Windows 10 LTSC 1809 (17763.1728).

Am I out of luck?