JNI, addNotify() and HWND

Hi
I'm using a Canvas as a target for some C++ rendering code. I have a native method to collect the HWND in addNotify() and some shut down code in removeNotify() - all pretty basic stuff, and it works fine.
However, I've noticed that resizing the Canvas results in calls to addNotify()/removeNotify(). Is there any guarantee that the Canvas will have the same HWND after a resize operation?
Regards,
--Jon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Hi thr ! I looked at ur work on tray icon utility ..it's a very fine piece of work...
Well I am a newbie to windows system calls from c++ ... Can u offer me a help to find a tutorial on this in the internet /.. i couldnt find one... thts y...
Thx in advance....

Similar Messages

  • JNI MMX and Java long arithmetic

    I am having trouble with a JNI call to a C program which contains assembler which uses an MMX operation as follows:
    static inline int diffPixels(int rgb1, int rgb2) {
    register int temp;
    __asm__ __volatile__ (
    "movd %1, %%mm1\n\t"
    "movd %2, %%mm2\n\t"
    "psadbw %%mm1, %%mm2\n\t"
    "movd %%mm2, %0\n\t"
    : "=r" (temp)
    : "r" (rgb1), "r" (rgb2)
    : "mm1", "mm2", "cc"
    return temp;
    After the JNI call returns, the first Java long arithmetic fails. I believe the failure is that when a method on a Java object returns a long the result is 0x8000000000000000 rather than the correct value.
    To use pure Java means my response to a user action is 9 seconds rather than 3 seconds with the JNI call which is why I want to persist with it. At present I am doing an arbitrary long multiply after the JNI call to "fix" long arithmetic but I am afraid this won't work if there is a context switch to another java thread in the middle of the JNI call.
    The test environment is a 3 Gigahertz Pentium 4 running Linux kernel 2.6.9 and Java version 1.4.2_06-b03.
    Can anyone explain this behaviour ? It took me days to isolate the problem.

    Hi,
    Is it absolutely necessary to declare temp as register ?
    How about adding a lock directive at the beginning of your asm ?
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                           

  • JNI, Solaris and Signal 11

    There are a number of bugs in the database that have the following attributes:
    -JNI
    -Solaris
    -Signal 11 exceptions.
    -Long running applications.
    I am experiencing something similar. I was using C threads for some call back functionality (and of course registering it them with JNI.) I was hoping that starting the threads with java would help but it didn't.
    I have several questions:
    -Has anyone found anything that allows them to work around this? Doesn't matter what you think it was - like a different switch on an application server. I am just curious if anyone thinks they solved it in any way.
    -Does anyone have an idea what might cause it? Even an just an idle thought?
    -Does anyone have a long running application, that uses JNI on Solaris and they don't experience this (obviously the JVM itself does this, but I am still curious?)
    -And slightly different that the above, does anyone have a long running JNI Solaris application using C threads that doesn't have this problem?

    jschell, are you still experiencing this?
    You may have seen some of my posts before... I have seen many of yours. But I hadn't seen this one until now, by chance.
    I am running on Solaris 8 with Java 1.3.1_03 and have a multithreaded C/C++ program that invokes the JVM and makes calls into Java via JNI. Actually, I have a few programs like this, but a particular one is set up to run as a daemon and eventually (after a couple of hours) runs into a segmentation fault (signal 11). The stack in the core file when the program fails shows that a thread started in the native code attempted "AttachCurrentThread()" and then a segfault happens way down in the JVM somewhere. However, I had an issue like this previously and I tracked it down (unexpectedly) to a memory leak in a totally unrelated portion of the native code. So I am trying to find other memory leaks in the code using tools like Rational Purify but it is tricky to get Purify and the JVM to play nicely together.
    Additional info: I have all latest patches applied, not using signal handlers, and am using the "alternate" thread library in /usr/lib/lwp.
    - I have another similar program on Solaris that does not seem to have this problem.
    - The same program that's crashing on Solaris seems to run OK on both Windows and HP-UX.
    Given the above, I am pursuing the avenue of a memory corruption in the native code as that has turned out to be the cause of numerous other problems in the past, but I am having a very hard time with this one. jschell (or anyone else), please let me know about your status and what you think.
    Thanks -
    Chris

  • JNI, MinGW and XP

    I'm developing some native code on my Windows XP machine (it's a recent upgrade), and I can't get the native methods to work. I'm using the MinGW compiler, which has worked wonderfully in the past...
    I notice, however, that there are some differences in the compiler now, that were changed since I last worked with JNI a few months ago. I downloaded the files from the Java Tutorial verbatim http://java.sun.com/docs/books/tutorial/native1.1/index.html, and they didn't work. Here's the error I get:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: displayHelloWorld
            at HelloWorld.displayHelloWorld(Native Method)
            at HelloWorld.main(HelloWorld.java:9)I find it interesting that the ULE isn't about a lack of a library, so hello.dll is being found correctly, but somehow the method implementation is incorrect. Are Java and C now out of sync? I've tried compiling as both C and C++ code. Like I said, this used to work fine, the only changes that have happened since it used to work are WinXP and a different C specification (apparently).
    This work is for a class, so I'd really appreciate a speedy reply. Thanks!!
    Ryan W Sims
    [email protected]

    Fixed:
    I ran nm hello.dll to try and see if the symbol Java_HelloWorld_displayHelloWorld existed in the dll, and I got this line:
    1000119e T _Java_HelloWorld_displayHelloWorld@8The problem is the '@8' on the end. You have to pass the "--kill-at" option to strip the "stdcall suffixes" (whatever those are) from the symbol names. To do this, I ran the following command:
    C:\javastuff\NativeTest>gcc -shared -Ic:\java\include -Ic:\java\include\win32 HelloWorldImp.c -o hello.dll -Wl,--kill-atThis fixes the problem.

  • Jni COM and MORE

    hello
    i'm french student and i try to make a program to use program in C and other language(Matlab for example) in a JAVA class.
    I would know ,if with a COM object we can permit at a java program to use any functions which are developped in other language.
    And if we can use COM object to call ,in Java class, functions wich are stockpiled inside DLL.
    I have made an experience with JNI and DLL based on c program ,but it is a very long and constraining way to realize a litle execution .
    I search an over way to developpe more easly this project.
    Sorry for my english
    if you have understand my question and if you have any document or idea on subject I'mwaiting your response
    thanks for your attention

    This is a complex issue:
    The simple answer is use JNI
    For a really good book on this topic, including COM integration, I recommend Stuart Halloway's excellent book "Component Development for the Java Platform" ISBN 9 780201 753066
    Stuart has developed a JNI helper system call JAWIN, whixh I have used to access COM objects. I have used this to insert data into Microsoft Outlook, for example.
    Hope this helps ....

  • JNI, OutOfMemory and OutOfSwap

    Hi all,
    I have a JNI method like this
    jbyteArray Java_util_LibraryUtil_rsEncode(JNIEnv *env, jobject obj)
    ReedSolomonCCSDS* reed ;
    try
    reed = new ReedSolomonCCSDS(useDualBasis, dualBasisPower);
    catch(...)
    exit(1);
    delete reed;
    When my Java native method is called, this function is executed but causes the "VM Memory Size", RSS, Total Memory increased endlessly if it is called many times (above 80.000 times). At the peak hour, the OutOfMemory is thrown with the OutOfSwap question.
    I'm using RedHat Linux 9 and JDK 1.5.0. The "VM Memory Size" is watched by the System Monitor Tool of Linux.
    The question is:
    - why is the memory still increased even I tried deleting the ReedSolomonCCSDS object?
    - If I try to use C, replace the "new" method by "calloc", replace "delete" by "free", the problem is solved. What is the different?
    Thanks in advance,

    The question is:
    - why is the memory still increased even I tried deleting the ReedSolomonCCSDS object?
    - If I try to use C, replace the "new" method by "calloc", replace "delete" by "free", the problem is solved. What is the different?
    Your "calloc" remark triggered something ... just a wild guess: shouldn't you use
    'delete [] reed' then?
    kind regards,
    Jos

  • Make JNI String and jsize global

    How can I make a string and an int global?
    I want to make jnitstr and strsize, ie the the string data and the string size global and accessiblee outside JNI methods, ie in C functions.
    const jbyte *jnistr;
         jsize strsize;
         jnistr = (*env)->GetStringUTFChars(env,prompt,NULL);
         if(jnistr==NULL){
              return;
         strsize = (*env)->GetStringLength(env,prompt);
    Thank You,

    Thanks...
    I just declared a char array outside all function definitions char buf[BUFSIZ];
    and when I am using it in a functions, I used this extern char buf[BUFSIZ];
    If I want to access the elements of this array, which is being populated in some other function...,
    then how can I do it...
    I am returning this array to a java method.
         for(i=0;i<37;i++){
              (*env)->SetObjectArrayElement(
                   env,ret,i,(*env)->NewStringUTF(env,buf));     
              printf(buf[i]);
    When I declare the elements like buf[i], then I am getting an error on compilation.

  • Using different JREs to compile and run JNI program

    Hi,
    Is it possible to use a JRE to compile a JNI program and then use another JRE to run it? For example, I'm compiling my program linking with Sun's libjvm.so and libjava.so. But at run time, I'll change my LD_LIBRARY_PATH to point to IBM's libjvm.so and libjava.so. Would it work at all?

    Oh I forgot to mentioned that I'm trying to invoke JVM in a C program to execute pre-compiled java byte code. (my bad... should've made that clear) So when I say "compile", I mean to compile C files instead of java files. So my original question is: is it possible to compile a C program invoking JVM linking with java and jvm libraries from vendor A and then at runtime, swapping java and jvm libraries with the ones from vendor B? (Since libjava.so and libjvm.so are dynamic libraries, it should work. But I was just making sure...) After some testing, I was able to compile my C program linking with Sun's libraries and to run it with IBM's libraries.

  • Sample programs and docs on JNI

    I am a green been to JNI, could you please point me to the sample source programs and docs to start reading from the basics. Thanks.

    Sun's JNI docs:
    http://java.sun.com/products/jdk/1.2/docs/guide/jni/spec/jniTOC.doc.html
    if you're developing on Unix, this link is helpful:
    http://ringlord.com/publications/jni-howto/
    and of course step-by-step beginner's guide to 1st working JNI program:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    This link also looks intersting for fast troubleshooting:
    http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
    Njoy!

  • JNI header files and /include

    Does anyone know where the JNI classes and what .jar file if need be or just what classes jni.c header file(s)are dependant upon, and do they reside in JRE 1.3.0 or 1.3.1, or do I need the JDK version to obtain these, also isn't there suppose to be a JAVA_HOME/include directory where JNI stuff is or at all, or did that all change in 1.3 and up. I thought I remember there being one 1.17 and 1.2ish JDK's if not JRE installs. Any help would be greatly appreciated. Thanks. Trask.

    and what jar are they in or what is the path to them from JAVA_HOME

  • Rational Purify and JNI

    All,
    has anyone managed to get Purify to run in conjunction with JNI? I was planning on instrumenting the native library with the Purify API, but apparently Purify cannot handle shared libraries:
    purify CC $(OBJECTS) -compat=4 -DSOLARIS -D_STRUCTURED_PROC=1 -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -G -L./ -lC -o libTst.so
    Purify 2002a.06.00 Solaris 2 (32-bit) Copyright (C) 1992-2002 Rational Software Corp. All rights reserved.
    Instrumenting:
    Purify engine: Error: Sorry, Purify cannot produce shared objects.
    make: *** [libs] Error 1

    Ooooops. Sorry for the stupid question.
    Actually the question i wanted to ask is, how to use purify with respect to a java program that loads a jni library and calls jni methods?
    Basically, the purify is used before the cc or gcc command while building the application. we can't use purify with java command or while compiling the C/C++ code to an object file. Then how to proceed?
    Pete, can u plz tell me, what exactly u hav done?
    -Sanghamitra

  • JNI CallVoidMethod problem.

    Hello all,
    I am learning JNI Language, and I have a CallVoidMethod problem.
    I get ERROR: The instruction at "0x6d494f54" referenced memory at "0x00000004". The memory could not be "read".
    Here is the code:
    <PRE>
    //========== Java Source =====
    class Test {
    private void javaMethod() {
    System.out.println("\n Java Method ");
    // Load Test.dll
    static {
    System.loadLibrary("Test");
    private native void create();
    public Test() {
         create();
    //========== C++ Source =========
    #include <jni.h>
    #include "Test.h"
    // Global
    JNIEnv *g_env;
    jobject g_obj;
    jmethodID g_mid;
    // JavaCallMethod
    void cMethod(JNIEnv *e, jobject o, jmethodID m) {
    e->CallVoidMethod(o,m);
    * Class: Test
    * Method: create
    * Signature: ()V
    JNIEXPORT void JNICALL Java_Test_create
    (JNIEnv *env, jobject obj) {
    g_env = env;
    g_obj = obj;
    jclass clazz = env->GetObjectClass(obj);
    g_mid = env->GetMethodID(clazz, "javaMethod", "()V");
    // ========== until here is all O.K. ============
    cMethod(g_env, g_obj, g_mid);
    // WndProc
    LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
    cMethod(g_env, g_obj, g_mid);
    // =========== ERROR =========
    // The instruction at "0x6d494f54" referenced memory at "0x00000004".
    // The memory could not be "read".
    </PRE>
    Sorry my English is not so well.
    Thanks for your help.

    Are you actually getting the windows callback, or are you sure the error is coming when you hit the first call to cMethod?

  • Calling a third-party library from JNI-enabled C++ code

    Hi everyone,
    I have some existing C++ application code that extracts data from a file in a special format (HDF5). This code uses a static library (third party) to decode the file format. I would like to wrap this application code in a JNI wrapper so that I can call the code from Java. So I have a situation like this:
    Java front end -> application code (C++) -> static library (C++)
    I have compiled JNI headers and modified the application code accordingly. I created a shared library by bundling the application code together with the static library (using gcc 3.2.2 on Red Hat Linux 9):
    g++ -shared hdf5_jni.cc -o libhdf5_jni.so -I<include path> -L<static library path> -lhdf5
    (the <static library path> contains the static library libhdf5.a). This creates a shared library which contains the application code and the relevant bits of the static library.
    When I call the Java front end, the shared library (libhdf5_jni.so) is correctly found and accessed. However, I get an UnsatisfiedLinkError which I don't understand:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: <blah>/lib/libhdf5_jni.so: <blah>/lib/libhdf5_jni.so: undefined symbol: _Z4formPKcz
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1485)
    ... etc
    I have no idea what the undefined symbol "_Z4formPKcz" represents. It's not part of the application code or the static library.
    Here's some more info that might help diagnosis:
    1) The problem seems to be due to the approach of having a three-step process (Java code calling bespoke shared library which includes unmodified 3rd-party code). I get an identical error (including the mysterious "_Z4formPKcz" symbol) when trying to do something similar with a different 3rd-party static library.
    2) When I simply have Java code calling C++ code which I have written myself (no calls to static library methods), I have no problems, i.e. there doesn't seem to be a problem with the way I set up the JNI wrappers or the application code, or in the way I create the shared library.
    3) When I simply have C++ code calling the static libraries (i.e. no Java wrapper) I have no problems, i.e. there doesn't seem to be a problem with the application code or the static libraries.
    4) The static libraries were compiled from source using the same compiler that I used to compile the application code.
    5) I'm using J2SDK 1.4.2 on Red Hat Linux 9, although I've tried other versions of the SDK and had the same problem.
    I've done a lot of web searches on the "_Z4formPKcz" symbol and have turned up absolutely nothing (zero Google hits!).
    Any help would be very much appreciated.
    Thanks, Jon

    Thanks chrisswhite,
    I should have mentioned that I tried this too and it didn't solve the problem. You're right though, I should be compiling with -fPIC anyway.
    Jon

  • Java Logger incrementing thread ids for a thread spawnned via JNI

    Hi all,
    I have a Java Logger object that I am passing to a JNI dll written in C++.
    If I spawn a thread from the JNI dll and log from that thread, the thread id in the log file increments for each log entry.
    To test this I wrote an infinite loop on the thread to make sure that the logging originated from a single thread. The thread id keeps incrementing in the log and the memory usage of the process increases too. However, the thread count in Task Manager does not increase.
    I will let the process run overnight to determine if the thread id will overflow or if an out of memory exception occurs.
    Has anyone else seen this behavior? Does anyone know what I might be doing wrong? I'm using jre 1.5.1.
    Thanks,
    William

    (1)
    has anybody ever tried to use a native library from
    JNI, when the library (Windows DLL) is not thread safe?
    Now we want many Java clients.
    That would mean each client makes its calls
    to the library in its own thread. Because the library
    is not thread safe, this would cause problems.Right. And therefore you have to encapsulate the DLL behind a properly synchronized interface class.
    Now the details of how you have to do that depends: (a) does the DLL contain state information other than TLS? (b) do you know which methods are not thread-safe?
    Depending on (a), (b) two extremes are both possible:
    One extreme would be to get an instance of the interface to the DLL from a factory method you'll have to write, where the factory method will block until it can give you "the DLL". Every client thread would obtain "the DLL", then use it, then release it. That would make the whole thing a "client-driven" "dedicated" server. If a client forgets to release the DLL, everybody else is going to be locked out. :-(
    The other extreme would be just to mirror the DLL methods, and mark the relevant ones as synchronized. That should be doable if (a) is false, and (b) is true.
    (2)
    Now we discussed to load the library several times -
    separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this
    way?The DLL is going to be mapped into the process address space on first usage. More Java threads just means adding more references to the same DLL instance.
    That would not result in thread-safe behavior.

  • JNI crash sockets

    I am trying to write a Java library around a piece of hardware that currently does not support Java. As the first part of the task, I need to establish a TCP/IP connection between a client and server. I wrote some test code in C that is very simple socket code that can be found on tons of example sites (yes I know Java has built in classes for this, but the connection must exist in the native side).
    I wrapped everything into a simple ConnectToServer and ConnectToClient functions (everything is hardcoded, so no parameters are passed) in a .so and can establish and run the connection without a hitch in a C++ program that loads the .so. When I load the .so and try to call the functions in a Java harness, the JVM crashes with a SIGSEGV in the server side during the accept call (the client does establish the connection, so it must be crashing somewhere pretty far into the accept( ) call). I have verified this crash by building and running the debug version of hotspot in gdb.
    Im running Red Hat Enterprise Linux Server release 6.1 (Santiago) and Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0-b17 mixed mode linux-amd64 compressed oops).
    Am I not allowed to call native library functions that have system calls in them during JNI, or am I missing something else that is not immediately obvious?

    jschell wrote:
    891860 wrote:
    I am trying to write a Java library around a piece of hardware that currently does not support Java. As the first part of the task, I need to establish a TCP/IP connection between a client and server. I wrote some test code in C that is very simple socket code that can be found on tons of example sites (yes I know Java has built in classes for this, but the connection must exist in the native side).Only reason I can think of for that would be because you need to pass the socket to your C code.
    So given that.
    1. Write C code that creates the socket
    2. Write an API in C that uses 1 to call the library.
    3. Test 1 and 2 via C code.
    After step 3 is complete you do the following.
    A. Determine the business functionality that your java application needs to access via the library. This step does not involve code at all. No C. No java.
    B. Write an API in C that implements the functionality determined in step A. And it will use code from 1/2 as well as needed.
    C. Write code in C to test B.
    After you have completed step 3 and step C then you write JNI and Java.Yes, the case is that the library that Im using for this device is in C, and requires a C socket. I did pretty much the steps that you mentioned. I wrote the basic network code. I wrapped it. Then I wrote a C program to load the .so and test it. It worked fine. When I added the JNI wrapper and Java code to launch it, that is when I had the problems.
    I removed everything but the basic TCP IP code (literally the wrapper that goes into JNI is just the TCP connection code). It still crashed. I then replaced the TCP IP code with another example I found on the net. Same issue. :(
    Edited by: 891860 on 17-Oct-2011 15:55

Maybe you are looking for

  • Container

    Hi Iam creating container element in workflow and after iam trying to setup mail. when iam right click and say create maiil and its coming before that container element. I want this after container element.. Ex workflow started-----container-mail----

  • Firefox will not allow me to print.

    Whenever I attempt to print it says "Before you can perform printer-related tasks such as page setup or printing a document, you need to install a printer. Do you want to install a printer now?"Printing works with all other applications including Mic

  • Velocity Templates - output an XML File

    Greetings, I'm a bit stuck on finding a way to have a Servlet using Velocity Templates, output an XML file. I know how to set the mime type and all that jazz in the Velocity Template. My problem is that all templates seem to be wrapped with the .htm

  • OCR Vote Disk got corrupted

    hi friends i am curious to know what will happen to the database if ocr/votedisk either of them or both of them got corrupted. I hope it will still run as a standalone database.........am i coorect. Thanks you all

  • How do I get the bin allocation of A/P Invoice using Crystal Report

    Hi, I have been trying to get the bin allocation from the A/P Invoice using tables OBTL and dbo.b1_OINMWithBinTransfer The OBTL is able to provide the messageID for other transactions but not for the A/P Invoice. Below is my sample code to exhibit th