This discussion is archived
6 Replies Latest reply: Mar 13, 2012 4:06 PM by jschellSomeoneStoleMyAlias RSS

JNI native win32 Sendmessage is not working properly

904134 Newbie
Currently Being Moderated
native Win32 sendmessage works only for some messages. (From a java application to a WndProc in C#)

I can send message like WM_CLOSE but it never send message like WM_COPYDATA (The WndProc never even receive the message)

Is there something particular with SendMessage under jni ? is there any java example of using a WM_COPYDATA to send data to something else than java? ( I tried the example somewhere in JNI and another example found on the internet and it's never working as expected since the message is never sent

Thanks,

Michel
  • 1. Re: JNI native win32 Sendmessage is not working properly
    EJP Guru
    Currently Being Moderated
    Is there something particular with SendMessage under jni ?
    Not very likely, is it?
  • 2. Re: JNI native win32 Sendmessage is not working properly
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    901131 wrote:
    native Win32 sendmessage works only for some messages.
    Unlikely. But if so it is a windows problem and has nothing to do with java nor jni.
    (From a java application to a WndProc in C#)
    SendMessage(), presumably what you are referring to, is used to send to a HWND.

    Neither the method nor the destination has anything to do with Java nor JNI.
    and it's never working as expected since the message is never sent
    Two guesses.
    1. You are attempting to use SendMessage() to interact with a Java GUI component. If so then you need to start with the understanding that such components are not the same as windows components.

    2. The target HWND has nothing to do with java. So STOP using jni to try to figure out what the problem is. Instead write a C++ app (no java at all) that does what you want. If it doesn't work then ask on a windows forum. AFTER it works then write JNI to invoke it from your java app.
  • 3. Re: JNI native win32 Sendmessage is not working properly
    904134 Newbie
    Currently Being Moderated
    My goal was to transfert some data from the java application to a C# application with WM_COPYDATA.

    Most sendmessage seems to work (ex: WM_CLOSE) but other message like WM_COPYDATA are **NEVER** even received by the WndProc.

    - I know that there is no native layer for java (of course)
    - > The target HWND has nothing to do with java
    This is not really true since the message is not sent and the target handle never receive it. The same exact message an hello world copy data works perfectly in C#, C++ and WPF

    My own guess is that the structure sent in the sendmessage parameters is somehow rejected for obscur reasons and never sent. WM_COPYDATA is particular and use structure in memory.

    The stange thing is that even if lparam wparam are invalid the message is received when sent with anything else than java/jni...that's why i was asking if there something particular to prevent some message the be sent to the destination handle.

    As a workaround we use a textfile to transfert the data but I want to know if anybody here has succeded sending a copydata message to another win32 application (c++ c#) ???
  • 4. Re: JNI native win32 Sendmessage is not working properly
    EJP Guru
    Currently Being Moderated
    The point is that JNI cannot possibly have any effect on this problem. You're looking in the wrong place. You have a coding problem, a parameter value problem, a build problem, ...
  • 5. Re: JNI native win32 Sendmessage is not working properly
    904134 Newbie
    Currently Being Moderated
    I was just wondering if anybody here has ever use jni to send a WM_COPYDATA (...but it's too specific...anyway)

    Will check MY OWN code a little bit closer to understand why it fail

    Thanks again :)

    Michel
  • 6. Re: JNI native win32 Sendmessage is not working properly
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    901131 wrote:
    My goal was to transfert some data from the java application to a C# application with WM_COPYDATA.

    Most sendmessage seems to work (ex: WM_CLOSE) but other message like WM_COPYDATA are **NEVER** even received by the WndProc.
    And how are you doing that given that SendMessage takes a HWND and java "applications" do not have the same relation to HWND as a windows application would if it looked the same?

    That fact that it works in one case only means that you found one case in which the relationship works. It doesn't mean that any others will.
    My own guess is...
    As I said before...there is no direct correlation from HWND to java components.
    As a workaround we use a textfile
    That would be my first solution since it doesn't require one to guess/debug to find obscure relationships which might change with the next minor release version of the VM.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points