Hi,
(Sorry if you receive this message twice, I had a problem subscribing to this
list.)
I want to use the SendMessageTimeout function located in user32.dll. The syntax
of this function is:
LRESULT SendMessageTimeout(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam,
UINT fuFlags,
UINT uTimeout,
PDWORD_PTR lpdwResult
);
I've translated this into the following Java interface:
public interface User32 extends com.sun.jna.examples.win32.W32API {
User32 INSTANCE = (User32) Native.loadLibrary("user32",
User32.class, DEFAULT_OPTIONS);
int HWND_BROADCAST = 0xffff;
int WM_SETTINGCHANGE = 0x001A;
int SMTO_ABORTIFHUNG = 0x0002;
int SendMessageTimeout(HWND hWnd, int msg, int wParam, String
lParam, int fuFlags, int uTimeout, int out);
}
I want to use this function to reload the environment variables from
the registry.
I have C++ code that does the following:
DWORD dwReturnValue = 0;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)
"Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
I want to do the same in my Java code:
User32 user32 = User32.INSTANCE;
HWND hwnd = new HWND();
hwnd.setPointer(new IntByReference(User32.HWND_BROADCAST));
user32.SendMessageTimeout(hwnd, User32.WM_SETTINGCHANGE, 0,
"Environment", User32.SMTO_ABORTIFHUNG, 5000, 0);
(I took the values for the constants from this site:
http://ghouston.blogspot.com/2005/08/how-to-create-and-change-environment.html)
However, this doesn't work. I receive error code 1400 (Invalid window
handle).
Can anyone tell me what I'm doing wrong here?
regards,
Maarten