-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Added the line in CHANGES.md. |
…32/User32WindowMessagesTest.java detected by travis with jdk 6.
Some more comments - please:
|
Corrected comments and license info.
Merge done and comments with license info corrected. |
Merged - thank you. |
This pull request contains the following code modification to jna-contrib :
Please add it to the main jna contrib distribution as it may be useful for others.