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

Addition win32 api : SendMessage, GetActiveWindow, COPYDATASTRUCT and a few constants + a demo application #774

Merged
merged 8 commits into from
Mar 19, 2017

Conversation

cnico
Copy link
Contributor

@cnico cnico commented Mar 1, 2017

This pull request contains the following code modification to jna-contrib :

  • Added mapping of win32 api : SendMessage and GetActiveWindow.
  • Added some constants and structures (COPYDATASTRUCT and CWPSTRUCT) from the win 32 api.
  • Added a Win32WindowMessagesDemo to demonstrate complex messages exchange through WM_COPYDATA and with a hooked winproc.

Please add it to the main jna contrib distribution as it may be useful for others.

Added some constants and structures (COPYDATASTRUCT and CWPSTRUCT from the win 32 api.
Added a Win32WindowMessagesDemo to demonstrate complex messages exchange through WM_COPYDATA and with a hooked winproc.
Copy link
Member

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - in general this looks good. I added a few comments inline, which I'd like you to have a look at.

In addition to the inline comments:

  • please add your work to the CHANGES.md file (have a look at the other entries and follow the pattern established there)
  • could the sample be converted into a unittest to execute the added structures?

}

public ULONG_PTR dwData;
public DWORD cbData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be mapped to int instead (DWORD and int both reference 32 bit wide data), that makes it easier to deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type change to int done with new commit.

* Defines the message parameters passed to a WH_CALLWNDPROC hook procedure, CallWndProc.
*/
public class CWPSTRUCT extends Structure {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the structure is generally passed in from outside, I'd add a no-arg constructor for completeness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added no-arg constructor with new commit.


public LPARAM lParam;
public WPARAM wParam;
public UINT message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be public int message, which would bring the signature in line with the SendMessage and SendMessageTimeout methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type change to int done with new commit.

// DEMO 2 : send of structured message.
COPYDATASTRUCT copyDataStruct = createStructuredMessage();
result = User32.INSTANCE.SendMessage(hwndPing, WinUser.WM_COPYDATA, null /* No current hwnd for this demo */,
new LPARAM(copyDataStruct.getPointer().getLong(0)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the copyDataStruct.getPointer().getLong(0) looks wrong. I asume Pointer.nativeValue(copyDataStruct.getPointer()) is what you mean. Also it might be worth mentioning in the comments, that copyDataStruct must be held strongly on the java side. In the sample this is archived by reading from the structure (line 92), but if that would not present, copyDataStruct becomes eligible for GC potentially to early. This leads to difficult to track down errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected and commented with new commit.

…t : cf java-native-access#774

* Replaced Win32WindowMessagesDemo.java by User32WindowMessagesTest.java
* changed data types to int where appropriate
* added pull request in CHANGES.md
@cnico
Copy link
Contributor Author

cnico commented Mar 12, 2017

Added the line in CHANGES.md.
Removed the Win32WindowMessagesDemo.java and created a unit test instead : User32WindowMessagesTest.java.

@matthiasblaesing
Copy link
Member

Some more comments - please:

  • Merge master (release of 4.4.0)
  • Adjust headers of User32WindowMessagesTest.java:
    • License should be AL2.0 + LGPLv2 (see other files)
    • You are not Daniel
    • this year is not 2010

@cnico
Copy link
Contributor Author

cnico commented Mar 17, 2017

Merge done and comments with license info corrected.

@matthiasblaesing matthiasblaesing merged commit 32ea99a into java-native-access:master Mar 19, 2017
@matthiasblaesing
Copy link
Member

Merged - thank you.

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

Successfully merging this pull request may close these issues.

None yet

2 participants