CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2006
    Posts
    11

    Question I love themouse! why won't he speak to me?

    Hello my fellow programmers,
    excuse my lame English...

    I've been searching for months for someone to help me on this,
    I'm a Java programmer, but there some things that java just can't handle...

    I need to get the mouse coordinates on windows.
    herer the deal:
    I program in Java, so i need someone to write me a tiny bit of code in C++ to help me complete a project I'm working on.

    [Clerification: The mouse coordinates needed are the screen ones, NOT the application ones. Moreover, the mouse should be free to work on WIN, untill the mouse middle button is clicked and from there on untill it is released, coordinates needs to be captured]

    contact me on my ICQ# 196601267
    (please! its my 12G project...)

    Programmers unite!...
    Hack the planet...
    blah blah blah...

  2. #2
    Join Date
    Oct 2005
    Posts
    230

    Re: I love themouse! why won't he speak to me?

    Is this going to be windows based, or does your project require it to be used on different operating systems?

  3. #3
    Join Date
    Feb 2006
    Posts
    11

    Re

    Only on windows for now...
    will u contact my icq?

  4. #4
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: I love themouse! why won't he speak to me?

    Have a look at this function:
    GetCursorPos()
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  5. #5
    Join Date
    Oct 2005
    Posts
    230

    Re: I love themouse! why won't he speak to me?

    I will try to help as much as possible but i do not have alot of time at the moment as i am already working on a large project.

    Could you please post more specifics of what you require?

    Thanks,
    P.S. (i do not have ICQ)
    You can send me an e-mail if you wish, tho i cannot give this prioritay over what i am already required to do.

  6. #6
    Join Date
    Feb 2006
    Posts
    11

    Smile Re:JNI

    Thank you for your time, I really apreciate it.
    It really sould not take a long time after we'll understend each other.

    What is needed is integration of Java and C++,
    a known interface which binds the two is JNI.

    You should build a DLL file according to the JNI coding conventions (as they are stated below in the file) and then Java could call native functions declared on your DLL.

    first we need to agree on what functions should be declared on the dll and then u could write them.

    My idea is that I will call a function from ur dll which we'll call accept(), and then at ur side, the function waits for a middle mouse dragging action, which while at it, the function shall save the coordinates of the mouse, and when the middle mouse button is relased the function should return the coordinates.

    (first u need to install java toolkit from sun.com so u'll have "jni.h" libary)

    An unlimited array, called "Vector" in java, is spose to be returned from ur function.
    the only thing I'm worried about is how will u create a java Object such as Vector, maybe in C++ u have ur own array type but u cant just send it back I guess...

    here is the interface declared on "Test.h":

    /* it is machine generated */
    #include <jni.h>
    /* Header for class Test */

    #ifndef _Included_Test
    #define _Included_Test
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class: Test
    * Method: accept
    * Signature: ()Ljava/util/Vector;
    */
    JNIEXPORT jobject JNICALL Java_Test_accept
    (JNIEnv *, jobject); //function declaration, dont change it, implement it

    #ifdef __cplusplus
    }
    #endif
    #endif

  7. #7
    Join Date
    Feb 2006
    Posts
    11

    Arrow Re: PLAN B, just in case

    In case the Vector thing wont work, a plan B is needed: just implement the next functions that
    a. checks is the middle mouse is down.
    b. returns the mouse x
    c. returns the mouse y
    (probebly sums in slower actions)

  8. #8
    Join Date
    Oct 2005
    Posts
    230

    Re: I love themouse! why won't he speak to me?

    Ok, ive never done anything like this b4 in terms of JNI, so its completely new to me..

    however just to see if we are on the right path counld you please test the following attachment. Small steps are good steps

    Thanks,
    Daniel
    Attached Files Attached Files

  9. #9
    Join Date
    Oct 2005
    Posts
    230

    Re: I love themouse! why won't he speak to me?

    If the above worked (i have no way of testing it) then try the folloing, it should be another step in the right direction..

    With this one you should get a messagebeep on every mouse event.

    Thanks
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2006
    Posts
    11

    Lightbulb Re: I love themouse! why won't he speak to me?

    thank u again for helping me, and dedicating ur time,
    I've been searching for months for somebody...

    I tried the first DLL and got the next response for the following main func.:

    public static void main(String ar[])
    {
    System.out.println("Hello world from Java");
    Test test = new Test();
    test.accept();
    }

    output:
    Hello world from Java
    Exception in thread "main" java.lang.NullPointerException
    at Test.accept(Native Method)
    at Test.main(Test.java:13)
    Hello Form C++ Dll
    ^^^^^^^^^^^^
    meaning, ur function was called succesfully. we can say that for sure by the output. but an exception followed the input, sont know why. i guess its because of the "return" or Vector...

    the second DLL output:

    Hello world from Java
    Exception in thread "main" java.lang.UnsatisfiedLinkError: accept
    at Test.accept(Native Method)
    at Test.main(Test.java:13)


    I dont know what u wrote into both of the dll's, so send me the source so i could too understend what was intended to happen, what succesfuly happend or didn't happen. so we could discuss further tries.

    for now, lets try the simple interface stated below which allows me to get the mouse x coord - this will be a good "return" try app:
    [special attention to the return type called "jint" (java int i spose), do u know how to return that kind of type?]

    /* machine generated */
    #include <jni.h>
    /* Header for class Test */

    #ifndef _Included_Test
    #define _Included_Test
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class: Test
    * Method: getMouseX
    * Signature: ()I
    */
    JNIEXPORT jint JNICALL Java_Test_getMouseX
    (JNIEnv *, jobject); //the same routine... implementation needed

    #ifdef __cplusplus
    }
    #endif
    #endif
    Last edited by eyalW12; February 19th, 2006 at 04:23 PM. Reason: i wanna emphsize something

  11. #11
    Join Date
    Feb 2006
    Posts
    11

    Re: I love themouse! why won't he speak to me?

    Following whats written above, my last response,
    I found this next page which i think specify an example as to how u can return java types from c++
    http://www.devarticles.com/c/a/Java/...-JNI-Part-2/2/

    [u really need to install icq (www.icq.com) ]
    Last edited by eyalW12; February 19th, 2006 at 05:14 PM. Reason: adding something...

  12. #12
    Join Date
    Oct 2005
    Posts
    230

    Re: I love themouse! why won't he speak to me?

    Hi eyalW12,

    good to know what first example at least called the function..

    I have other commitments today however i have installed ICQ (324054990) and i should be able to spend some time on it tonight (in about 6-7 hours time).

    Thanks

  13. #13
    Join Date
    Feb 2006
    Posts
    11

    Re: I love themouse! why won't he speak to me?

    k, i see u added me.
    be online on ICQ when u're free

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured