Thanks :)
Is this a confirmation that there is no support for Desktop Duplication API in the current state?
Thanks :)
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/d53241de-c682-43ae-9cd4-c3eadce0984d%40googlegroups.com.
Davide,There is "support" in the case that the base JNA functionality will easily allow you to create an interface and map the functions.Just because someone hasn't mapped a function yet doesn't mean it's "not supported".
On Fri, May 29, 2020 at 11:17 AM Davide Perini <sblan...@gmail.com> wrote:
Is this a confirmation that there is no support for Desktop Duplication API in the current state?
Thanks :)
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/d53241de-c682-43ae-9cd4-c3eadce0984d%40googlegroups.com.
--Dan Widdis
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/62ed9f37-22c5-4f1a-b8cd-94ceb2b740e1%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/CANb1Va6gZJ8AfvTMpmQY-GMs-RNT4uAOvVToqgpfTEQzyG_78g%40mail.gmail.com.
I’d recommend using Maven for dependency management. Pick one of many online tutorials for setting up a Maven project in IntelliJ, and then add the JNA project’s artifacts as dependencies:
<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
Others may prefer ant or Gradle, which give more flexibility. For me, Maven is simpler.
From: <jna-...@googlegroups.com> on behalf of Davide Perini <perini...@dpsoftware.org>
Reply-To: <jna-...@googlegroups.com>
Date: Sunday, May 31, 2020 at 10:21 AM
To: <jna-...@googlegroups.com>
Subject: Re: Please add Windows 10 Desktop Duplication API support
Hi,
thanks for the kind answer, I really appreciate it.
I would really like to learn JNA and give my contribute but at the moment I need to be sincere, I'm not able to do it and I don't have time to learn it without some good docs that shows the basics with step by step examples for simple APIs.
At the moment, I don't even know how to compile the project :)
Is this possible to do it via IntelliJ? Is there some guide on how to build using IntelliJ?
I will continue to look into the project and probably I will understand how it works one day and how to contribute.
Thank you.
Davide
Il 30/05/2020 02.05, Daniel B. Widdis ha scritto:
This is a perfect time to learn JNA! Mapping is straightforward. Declare an interface for the DLL you want to load (in this case, DXGI) and load the library.
Create a class Dxgi.java:
public interface Dxgi extends Library {
Dxgi INSTANCE = Native.load("Dxgi", Dxgi.class, W32APIOptions.DEFAULT_OPTIONS);
// structure and function mappings here
}
Here's a function mapping for https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgioutputduplication-acquirenextframe:
HRESULT AcquireNextFrame(int TimeoutInMilliseconds, DXGI_OUTDUPL_FRAME_INFO pFrameInfo, PointerByReference ppDesktopResource);
That requires the https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/ns-dxgi1_2-dxgi_outdupl_frame_info structure, map like this:
@FieldOrder({ "LastPresentTime", "LastMouseUpdateTime", "AccumulatedFrames", "RectsCoalesced",
"ProtectedContentMaskedOut", "PointerPosition", "TotalMetadatBufferSize", "PointerShapeBufferSize" })
class DXGI_OUTDUPL_FRAME_INFO extends Structure {
public LARGE_INTEGER LastPresentTime;
public LARGE_INTEGER LastMouseUpdateTime;
public int AccumulatedFrames;
public boolean RectsCoalesced;
public boolean ProtectedContentMaskedOut;
public DXGI_OUTDUPL_POINTER_POSITION PointerPosition;
public int TotalMetadataBufferSize;
public int PointerShapeBufferSize;
// may need constructor if you will create from a Pointer
}
That requires a https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/ns-dxgi1_2-dxgi_outdupl_pointer_position structure, map similarly, repeat nested mappings as necessary.
Look at almost any random class in the win32 platform mappings and you'll see ample examples:
Try and get started and feel free to ask here for help if you get stuck.
On Fri, May 29, 2020 at 4:30 PM Davide Perini <mailto:sblan...@gmail.com> wrote:
I don't know JNA so well, it's not that easy for me at the moment :D
Il giorno venerdì 29 maggio 2020 20:21:34 UTC+2, Daniel B. Widdis ha scritto:
Davide,
There is "support" in the case that the base JNA functionality will easily allow you to create an interface and map the functions.
Just because someone hasn't mapped a function yet doesn't mean it's "not supported".
On Fri, May 29, 2020 at 11:17 AM Davide Perini <sblan...@gmail.com> wrote:
Is this a confirmation that there is no support for Desktop Duplication API in the current state?
Thanks :)
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/d53241de-c682-43ae...@googlegroups.com.
--
Dan Widdis
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mailto:jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/62ed9f37-22c5-4f1a...@googlegroups.com?utm_medium=email&utm_source=footer.
--
Dan Widdis
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mailto:jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/CANb1Va6gZJ8AfvTMpmQY-GMs...@mail.gmail.com?utm_medium=email&utm_source=footer.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mailto:jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/a089023e-63ea-3158...@dpsoftware.org?utm_medium=email&utm_source=footer.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/74A86C45-37D5-481E-937B-3BF52728BD59%40gmail.com.
public interface Dxgi extends Library { Dxgi INSTANCE = Native.load("Dxgi", Dxgi.class, W32APIOptions.DEFAULT_OPTIONS);
WinNT.HRESULT AcquireNextFrame(int TimeoutInMilliseconds, DXGI_OUTDUPL_FRAME_INFO pFrameInfo, PointerByReference ppDesktopResource);
// structure and function mappings here }
@AllArgsConstructor // using Lombok to generate all args constructor @Structure.FieldOrder({ "LastPresentTime", "LastMouseUpdateTime", "AccumulatedFrames", "RectsCoalesced",
"ProtectedContentMaskedOut", "PointerPosition", "TotalMetadatBufferSize", "PointerShapeBufferSize" }) class DXGI_OUTDUPL_FRAME_INFO extends
Structure { public WinNT.LARGE_INTEGER LastPresentTime; public WinNT.LARGE_INTEGER LastMouseUpdateTime;
public int AccumulatedFrames; public boolean RectsCoalesced; public boolean ProtectedContentMaskedOut; public DXGI_OUTDUPL_POINTER_POSITION PointerPosition; public int TotalMetadataBufferSize; public int PointerShapeBufferSize; }
@Structure.FieldOrder({ "Position", "Visible" }) class DXGI_OUTDUPL_POINTER_POSITION extends Structure { public Pointer Position; public boolean Visible; }now in my main.java I do something like this
Dxgi dxgi = Dxgi.INSTANCE; DXGI_OUTDUPL_FRAME_INFO frameInfo = null; PointerByReference ppDesktopResource = null; dxgi.AcquireNextFrame(1,frameInfo,ppDesktopResource);but I don't know how to initialize the second and the third argument of the AcquireNextFrame method.
Great progress!
> but I don't know how to initialize the second and the third argument of the AcquireNextFrame method.
> Any suggestion on how to initialize that Structure?
This is where you have to read the Native API. It tells you what to do with each argument:
You’ll use the returned pointer value to instantiate an IDXGIResource interface. Defining that is a little more complex but once you get this pointer, I’ll walk you through that part. I’ve summarized the general steps in this StackOverflow answer but I’ll give more specific help for you here.
From: <jna-...@googlegroups.com> on behalf of Davide Perini <perini...@dpsoftware.org>
Reply-To: <jna-...@googlegroups.com>
Date: Sunday, May 31, 2020 at 1:48 PM
To: <jna-...@googlegroups.com>
Subject: Re: Please add Windows 10 Desktop Duplication API support
This project is so cool, can't wait to use it everywhere :)
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/d7ce6d0a-5a5b-40e6-18e9-9e17f240491d%40dpsoftware.org.
> The AcquireNextFrame seems to return a WinNT.HRESULT, but how can I use that result in Java?
HRESULT just extends NativeLong. Use its .intValue() method to extract an error code. 0 is success, other codes are explained here and those constant names are mapped in the WinErr class.
The COMUtils class has a method SUCCEEDED(HRESULT hr) which easily turns that into a boolean, and checkRC(HRESULT hr) which turns a failed result into a COMException. There may be other utilities.
From: <jna-...@googlegroups.com> on behalf of Davide Perini <perini...@dpsoftware.org>
Reply-To: <jna-...@googlegroups.com>
Date: Sunday, May 31, 2020 at 1:48 PM
To: <jna-...@googlegroups.com>
Subject: Re: Please add Windows 10 Desktop Duplication API support
This project is so cool, can't wait to use it everywhere :)
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/d7ce6d0a-5a5b-40e6-18e9-9e17f240491d%40dpsoftware.org.
Dxgi dxgi = Dxgi.INSTANCE; PointerByReference ppDesktopResource = new PointerByReference(); DXGI_OUTDUPL_FRAME_INFO frameInfo = new DXGI_OUTDUPL_FRAME_INFO(); dxgi.AcquireNextFrame(33,frameInfo,ppDesktopResource);
public interface Dxgi extends Library { Dxgi INSTANCE = Native.load("Dxgi", Dxgi.class, W32APIOptions.DEFAULT_OPTIONS); WinNT.HRESULT AcquireNextFrame(int TimeoutInMilliseconds, DXGI_OUTDUPL_FRAME_INFO pFrameInfo, PointerByReference ppDesktopResource); // structure and function mappings here }
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/7A1FECB0-65D2-4668-A8C2-EE4E33749DDF%40gmail.com.
Uh oh.
So, we’ve reached an instructive point in this exercise. First, you’ve learned how to map functions to JNA.
However, JNA works via libffi which is a C interface, not C++. In order to work with DLLs targeted to C++, those DLLs must export the functions to C.
In many cases, particularly with the Windows APIs, this is the case. However, in this particular case, it seems that this mapping isn’t possible directly.
I’ll step back and let brighter minds than mine give more commentary in case I’m missing something.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/cd40cc31-1e43-c874-fe94-cf90687ef552%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/D6A4AA40-68FE-49DE-BF13-04393EA9B776%40gmail.com.
Actually there is a solution posted many places on the internet, and it’s to write a C wrapper function to expose the C++ functions.
I understand your frustration, but the fault lies with library developers who do not expose their APIs to C. JNA is one of many cross-platform / cross-language programs relying on libffi and all suffer the same roadblock.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/6e93552c-7acb-c7e5-11e3-ec567a5ad9b6%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/B6EACEFA-6BB1-428D-93FD-E6EBCE98DBA3%40gmail.com.
As Obi-Wan would say, “Use the Source, Luke.” 😊
Take a look at the GDI32Util getScreenshot method implementation.
Copy that as a starting point, look at every case of “new X()” and see if you can re-use objects instead of instantiating them and disposing of them, that should save you the heap issues and delays with garbage collection. Are you compiling for JDK11 with faster GC?
I believe reusing objects was suggested to you in another email thread on this list, so check for that reply that had a lot more detail, I think.
The Memory object used as a buffer is a good starting point to re-use. Keeping the DataBufferInt around and just setting its value instead of re-instantiating it is another.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/ee70c9a3-9e93-6c65-ca1f-a33ecde4c9bb%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/94F2A536-C602-456E-956B-95C34BF76B6C%40gmail.com.
Based on browsing the docs from the link you provided, it appears (I’m guessing) these are in the WinRT dll file, and this stackoverflow answer implies there’s a C API.
Note this is still COM which is another layer of complexity (you have to locate the header file, find the VTBL which lists the pointers to each function in order, count them, and then use a com invoking function based on that index) but it seems it would be possible.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/17277a85cb0.2820.3c8a1e3a2388806d058c6e4a23c6ecab%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/2426B570-1336-44B4-B06B-DC86DD00D91D%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/B6EACEFA-6BB1-428D-93FD-E6EBCE98DBA3%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/eff589ff-710f-0809-555e-52f9781312fa%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/bb73314f665363a6fcbf1185cf13df9e163dcdc9.camel%40doppel-helix.eu.
public interface Dxgi extends Library { Dxgi INSTANCE = Native.load("Dxgi", Dxgi.class, W32APIOptions.DEFAULT_OPTIONS);
public WinNT.HRESULT AcquireNextFrame(int TimeoutInMilliseconds, DXGI_OUTDUPL_FRAME_INFO pFrameInfo, PointerByReference ppDesktopResource); }return this
No C wrapper for that function. You need a COM object per my previous answer.
You will create the COM object from a pointer that you will have to obtain using the API which generates that object… Matthias suggested one, you will have to search the API to find that, at which point you will:
Take a look at JNA WbemcliUtil and WbemCli class source code for similar types of things to what you will need to do.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/9adb2a65-5677-f4ab-0478-8f175a7032ec%40dpsoftware.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/CE08D7FF-E624-4B96-A9D9-5FCD97A82215%40gmail.com.