Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 197839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:53:15+00:00 2026-05-11T16:53:15+00:00

I’m trying to call SendMessage with an uint parameter from Java, but I can’t

  • 0

I’m trying to call SendMessage with an uint parameter from Java, but I can’t convert int to uint. I can’t change the uint parameter in SendMessage because it is a windows function. Is there some way of doing this?

Background:
I’m actually using Processing, and I’m following the following tutorials to access user32.dll: http://processing.org/hacks/hacks:jnative

and http://jnative.free.fr/SPIP-v1-8-3/article.php3?id_article=8

And I’m following this to call SendMessage
http://www.codeproject.com/KB/cs/Monitor_management_guide.aspx

Here’s my code, GetActiveWindow works fine, it’s from the second link above.

 int SC_MONITORPOWER = 0xF170;
 int WM_SYSCOMMAND = 0x0112;
 int MONITOR_ON = -1;
 int MONITOR_OFF = 2;
 int MONITOR_STANDBY = 1;

HWND ValidHWND = org.xvolks.jnative.util.User32.GetActiveWindow(); 
org.xvolks.jnative.util.User32.SendMessage(ValidHWND, (UINT)WM_SYSCOMMAND, 
          (WPARAM)SC_MONITORPOWER, (LPARAM)MONITOR_STANDBY);

last line is where the error happens, it says the expected UINT in type User32 is not applicable to the LONG I provided. I can’t modify SendMessage either

Here’s the corresponding java file the call above invokes, the GetActiveWindow part works fine since it’s from a tutorial. I’m trying to tailor Sendmessage to follow it, but I haven’t figured it all out yet. However, I don’t think it matters to the error I’m getting, since changing the parameters to SendMessage here doesn’t change what the compiler expects. I’ve tried changing int Msg to uint Msg to long Msg, the compiler still expects uint from the code above.

public class Paul_s_User32 extends User32 {
public HANDLE GetActiveWindow() {
    JNative GetActiveWindow = new JNative(DLL_NAME, "GetActiveWindow");
    GetActiveWindow.setRetVal(Type.INT);
    GetActiveWindow.invoke();
    HWND handle = new HWND(GetActiveWindow.getRetValAsInt());
    GetActiveWindow.dispose();
    return handle;
}
public IntPtr SendMessage(IntPtr hWnd, int Msg, 
          IntPtr wParam, IntPtr lParam) {
    JNative SendMessage = new JNative(DLL_NAME, "SendMessage");
    //SendMessage.setRetVal(Type.long);
    SendMessage.invoke();

    SendMessage(ValidHWND, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_STANDBY);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:53:15+00:00Added an answer on May 11, 2026 at 4:53 pm

    If you are using the org.xvolks.jnative package, all of the parameters (HWND, UINT, WPARAM, and LPARAM) are classes in org.xvolks.jnative.misc.basicStructures. So you should be able to do something like this (untested code):

    import org.xvolks.jnative.misc.basicStructures.*;
    ...
    
    User32.SendMessage(
        new HWND(ValidHWND),
        new UINT(WM_SYSCOMMAND), 
        new WPARAM(SC_MONITORPOWER),
        new LPARAM(MONITOR_STANDBY);
    

    For your reference, here’s the implementation of SendMessage in org.xvolks.jnative.util.User32. As you can see, the jnative code does not care at all about signed and unsigned. You might find it useful to grab the jnative source code.

    public static LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) throws NativeException, IllegalAccessException
    {
        JNative SendMessage = new JNative(DLL_NAME, "SendMessageA");
        SendMessage.setRetVal(Type.INT);
        int pos = 0;
        SendMessage.setParameter(pos++, hWnd.getValue());
        SendMessage.setParameter(pos++, Msg.getValue());
        SendMessage.setParameter(pos++, wParam.getValue());
        SendMessage.setParameter(pos++, lParam.getValue());
        SendMessage.invoke();
        pos = SendMessage.getRetValAsInt();
        SendMessage.dispose();
        return new LRESULT(pos);
    }
    

    And if you decide that you don’t like JNative, you could take a look at Java Native Access (JNA).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just curious why are you saving this in the base… May 12, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer // define a function pointer typedef __cdecl void (*your_function) (A… May 12, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer try a pattern similar to this INSERT INTO logs (blah,blah)… May 12, 2026 at 4:25 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.