Jump to content
Excelsior Forums
Sign in to follow this  
konczcsj

SetTimer in user32.dll

Recommended Posts

I am evaluating xFunction and I tried to use the timer services of user32.dll. I wrote a class Timer with the following code:

[pre]

import com.excelsior.xFunction.*;

import javax.swing.*;

public class Timer {

   public static void main(String[] a) {

       try {

           Callback timerCallback = new TimeoutCallback();

           xFunction f = new xFunction("user32","int SetTimer(int,int,int,TimeoutCallback)");

           Argument[] args = new Argument[4];

           args[0] = new Argument(0); //no window handle

           args[1] = new Argument(0);

           args[2] = new Argument(5000); //wait for 5 seconds

           args[3] = new Argument(timerCallback);

           int i = ((Integer)f.invoke(args)).intValue();

           System.out.println(" Timer Handle = " + i);

           //without the lines below the program exits immediatelly

           JFrame frame = new JFrame("SetTimer test");

           frame.setSize(100,100);

           frame.setVisible(true);

       } catch (Exception e) {

           e.printStackTrace();

       }

   }

}

class TimeoutCallback extends Callback{

   public String defineSignature(){

    return "void timeout(int,int,int,long)";

    }

    public void timeout(int a, int b, int c, long d){

        System.out.println("Timeout received!");

    }

}

[/pre]

Although the return value indicates success (i get a non-null timer ID), no call is made to my callback. What am I doing wrong here?

Share this post


Link to post
Share on other sites

Hi,

I think that the problem is in the SetTimer function, because the C version of such example do not work as well.

#include <windows.h>

void MyTimerProc(int a , int b, int c, int d) {
   printf("aaa\n");
}

int main(void) {
   int a = SetTimer(NULL,         
       0,                         
       500,                       
       (TIMERPROC) MyTimerProc); 
   printf("%d\n", a);
   getch();
}

To compile one may use the following command-line:

cl timer.c user32.lib

The description of the SetTimer is foggy and probably it  does not work if invoked with the first parameter NULL (hWnd).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×