Good afternoon,
I use JNA to interact with the Windows API, and now I'm stuck when creating a window. As far as I did the following: 1. Create a child window of an existing window and get a valid handler for it. 2. I realized that every window in Windows has a continuous cycle of sending messages. 3. I realized that the best way to include my window in the message sending cycle is to use something like the following code (not mine, but this is what I would do):
final LONG_PTR prevWndProc = new LONG_PTR(User32.INSTANCE.GetWindowLong(hwnd, User32.GWL_WNDPROC)); //this is to obtain a pointer to the WNDPROC of the parent window, which we are going to need later wndProcCallbackListener = new WndProcCallbackListener() { public LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam) { if (uMsg == WTSAPI.WM_POWERBROADCAST) { System.out.println("WM_POWERBROADCAST Event: hWnd="+hwnd+", uMsg="+uMsg+", uParam="+uParam+", lParam="+lParam); } else if (uMsg == WTSAPI.WTS_SESSION_CHANGE) { System.out.println("WTS_SESSION_CHANGE Event: hWnd="+hwnd+", uMsg="+uMsg+", uParam="+uParam+", lParam="+lParam); } //Call the window actual WndProc so the events get processed. return User32.INSTANCE.CallWindowProc(prevWndProc, hWnd, uMsg, uParam, lParam); } }; //Set the WndProc function to use our callback listener instead of the window one. int result = User32.INSTANCE.SetWindowLong(hwnd, User32.GWL_WNDPROC, wndProcCallbackListener);
However, my problem is that I call GetWindowLong () on the parent window (my first line of code) . I get 0 for a pointer that indicates that the function did not complete successfully. The subsequent call to GetLastError () and a quick check of the error codes give me the "Access Denied" error. This, of course, is logical, since I'm trying to access the WNDPROC address of another from my thread, but I was wondering if there is any way (of course, should be) to get around this.
Any pointers? (pun)
source share