Using AFX_MANAGE_STATE(AfxGetStaticModuleState()) in JNI..

Hi All,
I have a question.
This is the clearest explanation of using
AFX_MANAGE_STATE(AfxGetStaticModuleState())
that I've seen:
"By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:"
In my JNI code I don't knowingly use any MFC DLLs
and I don't use JNI to put up any Dialogs, just straight
ADSI and WMI code, so my question is, should I use
AFX_MANAGE_STATE(AfxGetStaticModuleState())
in my JNI code? My JNI DLLs are an important part
of my Servlets. Is it something like:
"It wouldn't hurt.."? :-)
Thanks,
Joe Siebenmann

Hi Maxim,
of course you can. There exists a mechanism called JNI (Java Native Invocation) as you already mentioned.
I guess using JNI is the easiest way to achieve what you want.
I don't have any knowledge in detail what causes your "java.lang.UnsatisfiedLinkError" - Error but it looks to me like the JVM isn't able to find your DLL which contains the native C/C++ - Code.
To help the JVM find the DLL or SO you have either to copy your DLL/SO in a globally known LIB-Directory or, which is better in my opinion, adjust der global libary path so it also points to YOUR DLL/SO by doing the following under
Unix or Linux:
  LD_LIBRARY_PATH=`pwd`
  export LD_LIBRARY_PATH
OR
Windows NT/2000/95:
  set PATH=%path%;.
I would also recommend to check out the following link:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
I hope this helps !!!
Best Regards,
Frank

Similar Messages

  • Using C functions with JNI

    Hello,
    I am just looking at JNI for the first time today. I have to write some utility functions in C for the a linux Red Hat 7 server, and then be able to call them from java applications. I am having some trouble when I try and compile the c source. I am not sure if this is a C error directly, or caused by the java. I am really sorry if this is a C error, its been awhile! I am simply trying to runt the demo on the java.sun.com site. Here is my code:
    The Java:
    public class HelloWorld {
    public HelloWorld() {
    public native void displayHelloWorld();
    static {
    System.loadLibrary("hello");
    public static void main(String[] args) {
    new JNITest2().displayHelloWorld();
    The c file:
    #include <jni.h>
    #include "JNITest2.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    printf("Hello world!\n");
    return;
    The .h file:/* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloWorld */
    #ifndef IncludedHelloWorld
    #define IncludedHelloWorld
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: HelloWorld
    * Method: displayHelloWorld
    * Signature: ()V
    JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    The Error I Get:
    [2943UK@hercules classes]# cc -g -I/usr/local/jdk1.3/include -I/usr/local/jdk1.3/include/linux HelloWorldImp.c -o libhello.so
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start':
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    Thanks in advance to anyone who knows the answer and can help me.
    Ian

    Sorry, Here is the java source I am using:
    public class HelloWorld {
    public HelloWorld() {
    public native void displayHelloWorld();
    static {
    System.loadLibrary("hello");
    public static void main(String[] args) {
    new HelloWorld().displayHelloWorld();
    }

  • Need to use default package for JNI code?

    Hi,
    I don't have much experience with JNI code, so excuse me if I make a silly mistake.
    I have a set of DLLs to interface with Microsoft native speech code ("Microsoft Sam") -- a GPL library called Quadmore. Quadmore has some sample Java code to work with the libraries, all of which they put in the default package (no package). If I move their code to a named package, it breaks. The Java code is able to load th libraries, but can't find any of the methods.
    Looking at the source for their DLLs (though I don't speak C++), the method names are things like
    JNIEXPORT jboolean JNICALL Java_QuadmoreTTS_SpeakDarling(JNIEnv *env,jobject obj,jstring strInput)As far as I understand, this implies that the QuadmoreTTS.class that calls the code must be in the default package, as otherwise the method name needs to be prepended with a package name.
    If that's so, then there's no way I can use the code as-is, right? Naturally, the rest of my program is in named packages, and I can't import any class that is in the default package, right? I've tried placing all their code in a jar and adding the jar to my classpath, but I still can't import any of their classes as they are in the default package.
    Is the only solution to re-compile all their C/C++ code to let it use packages? Am I being dumb and missing something? I'm pretty sure other people have used Quadmore before, so I can't believe that they've never had this problem before.
    Any suggestions greatly appreciated!
    Sam

    C/C++ functions in JNI must conform to the prototypes produced by running the javah compiler against the class file with native methods in it. So if you move the class to another package, the prototypes change. If you doun't change the compiled C coudes to suit, you will get undefined method errors when you load the dll as the JVM won't be able to match the native methods to the methods in the dll (it will call WinLoadLibrary() and WinLoadProcAddress() or somesuch under Windows).

  • Is JMF use hardware accelerated through JNI possible?

    Dear all:
    I try to use JMF decode MPEG-2 data, through VeXP which wrote in C.
    So I think we can call C library through JNI pass encoded MPEG-2 data to VeXP, use hardware decode encoded MPEG-2 data to YUV-format raw data then return it to JAVA.
    but JNI seem can't pass media raw data by call by reference...
    It should cause a lot of memory copy.
    How about it's feasibility?
    Have anyone give me some suggestion?
    Regards,
    white

    There's a few ways to do it, but I'd use a style sheet. So:
    1. Add this to the "creationComplete" Stage event:   sym.$("<link rel='stylesheet' type='text/css' href='styles.css'>").appendTo("#Stage");
    2. Create a style sheet (text file) in your project folder named "styles.css", and define a class:
    .force-webkit-acceleration {
         -webkit-transform: translate3d(0,0,0);
    3. Give your animated element the class "force-webkit-acceleration" in the properties panel (the little c-in-a-box icon next to the title field).
    Be sure that the style sheet file ends up in your "publish/web" folder too.

  • How to use VS2005 dlls with jni?

    Hello,
    I have a java application using jni and some dlls.
    Previously this dlls were created using VS2003. Now I want to use VS2005 and I
    encountered some problems.
    Everything is working on my station were I have installed VS2005 but when I try to run the
    application on other station (a test station) is not working.
    I get the following error:
    java.lang.UnsatisfiedLinkError: C:\App\Test.dll: This application has failed to start because
    the application configuration is incorrect. Reinstalling the application may fix this problem
         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
         at java.lang.ClassLoader.loadLibrary0(Unknown Source)
         ......First I tried to search all the dependences and copied all missing dlls from my work station to the test
    station in the application directory. Still not working.
    when dlls were made with VS2003 I had only 3 dependences: mfc71d, msvcp71d, msvcr71d. With this dlls in
    the application directory everything was fine.
    Second I tried to install .Net framework(2.0) and vcredist (VS2005_sp1) but still nothing.
    What I'm doing wrong? Is somebody which is using dlls made in VS2005 with jni?
    Thank you
    ,Dragos

    IIRC, that message means the manifest file in the DLL points to assembly that your computer doesn't have, or it has no manifest file.
    You either need to:
    -recompile using static linking so that it has no dependencies
    -stick the correct manifest in
    -include the entire SxS (site by side) assembly folders with your application (only the ones you're dependent on). These are found in something similar to:
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86

  • Using InDesign CS6 SDK with MFC

    Has anybody been developing InDesign plugins that use MFC? I would have to use a bunch of functions that rely heavily on MFC. The problem is that now both MFC and InDesign CS6 API want to declare their own CString, ICommand and DLLmain and it creates quite major conflicts. I'm just curious if there is a proven way to prevent these conflicts.

    Hi,
    yes, we've done so relatively successfully but "ne'er the twain shall meet"!
    We've encapsulated all access to MFC in a separate DLL.
    As per normal with an MFC based DLL you have to restore access to the MFC module globals
    using
            AFX_MANAGE_STATE( AfxGetStaticModuleState() );
    I don't think there's any other "magic" that you need to take account of.
    Good luck
    Caerwyn

  • Creating JNI DLL on WinXP using MinGW and GCC

    Ohh man, I spent entire day fighting with "UnsatisfiedLinkError "while trying to cal my native method. After reading all the posts with similar problems, and checking for every little thing that was suggested I figured it out. So I'm reposting the solution here since no one else had suggested this.
    The solution to my problem was that g++/gcc compiler needed an option "-Wl,--add-stdcall-alias". This was the killer. I had the "-shared", but it wouldn't link without the "-Wl,--add-stdcall-alias" option!!!
    As a summary, while its fresh in my mind, here are the trouble shooting steps I used:
    1) Check package names and the generated .h file using javah. I checked and rechecked the names, even created simpler static void method to try and get it to link.
    2) Make sure to use the "jobject" parameter for dynamic methods and "jclass" for static methods in the signature as second argument.
    3) That method name starts with "Java_" and I stress the CAPITAL "J", can not be lowercase. Although if you are using javah, that should not be the problem, since javah can not ommit this kind of detail. The only thing that you need to check for is that if you change method from dynamic to static, and don't rerun the javah, or javah doesn't replace the previous file. So make sure you restart clean and that javah regenerated the file with "jclass" or "jobject" whichever is the case.
    4) Used the "java -verbose:jni" debug flag to see my native method loaded. In my case when it wasn't working I couldn't see the method load, but there were no error messages from "System.loadLibrary" or from the verbose output. Only the UnsatisfiedLinkError. Frustrating. After the fix it loads perfectly:
    [Dynamic-linking native method org.jnetpcap.Pcap.openVoid ... JNI]5) I used "nm" found at "c:/MinGW/bin/nm.exe" to dump the symbol table, and I could see all my methods, with the appropriate named marked as text (T) flag. They were not being loaded when viewed using "java -verbose:jni" though.
    6) I put "extern "C" {}" around all my JNI C++ methods.
    7) Tried a gazilion other gcc options, posted in various messages, none worked.
    8) Finally came accross the "-Wl,--add-stdcall-alias" flag which fixed it.
    Here is a portion of my Makefile for reference:
    $(LINK_TARGET) : $(OBJS)
         g++ \
              -shared \
              -Wl,--add-stdcall-alias \
              -o $@ $^ \
              $(LIBDIRS) $(LIBS)LIBDIR and LIBS point to a single external library dependency.
    My IDE environment is Eclipse 3.2, but I run everything from Makefiles as external programs.
    I wish this was documented somewhere, would have saved me an entire day of troubleshooting.
    Cheers,
    mark...
    Message was edited by:
    voytechs - added CODE tags

    Glad my post helped out at least a few people.
    Believe it or not, I'm in the same boat now on Linux.
    Atleast I know its the name mangling problem again. I
    see a few symbols unmangled with nm, but most are,
    and those are then one's JNI is complaining about
    with UnsatisfiedLinkError.
    So now I'm going through various post related to
    linux and trying to find the same type of flag. The
    "alias" flag doesn't work with RH4 g++ version
    4.0.2.You should not need a flag on Linux. A typical compile for me on my Linux box is:
    gcc -shared -o libjnitest.so -I/usr/java/jdk1.6.0_01/include -I/usr/java/jdk1.6.0_01/include/linux jnitest.c>
    Window builds perfectly fine, but now I'm creating a
    new platform target. Everything compiles and creates
    the shared library, just can't get JNI to be happy.
    BTW, my project: http://jnetpcap.sf.net
    Ah. You have .cpp extensions on your filenames. Are you using gcc or g++ to compile? If you don't use g++, you can get errors such as:
    undefined symbol: __gxx_personality_v0
    Jim S.

  • How to open MSWORD using JAVA/JNI and write the database entries into WORD

    Hi..
    I am searching for java codes that uses JAVA NATIVE INTERFACE (JNI) for opening MSWORD 2003.
    To be brief.
    I created HTML form called Employee_data.
    if i click on Submit button a word document should be opened.This should be using JNI.
    I have also created a servlet in jsp to process the form data and store it into database(mysql).;
    Please help me to find the codes to open MSWORD on submit click and to write the database entries into word file.Can i get the full code for that.This is so urgent.
    Thanks in advance.

    Hi Suresh,
    The easest solution I can think of is to copy the math equation from the PowerPoint then paste in the Word document directly, there's actually no way to convert it to plain text, some equation is very complext, String variable is not suitable in this case.
    For example, this code works fine:
    var powerPoint = new Application { WindowState = PpWindowState.ppWindowMinimized };
    var oPresSet = powerPoint.Presentations;
    Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"C:\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
    var strObj = oPres.Slides[1].NotesPage.Shapes[2].TextFrame2.TextRange.MathZones.get_MathZones();
    strObj.Copy();
    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
    wordApp.Visible = true;
    Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add();
    doc.Range(0, 0).Paste();
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Using JNI to connect to a COM object

    Hi,
    I need to write an application in Java which uses a COM object. Has anyone tried to connect to/ use the functionality of a COM object by using the JNI (Java Native Interface)?
    I would highly appreciate any tips on how to go about it.
    Thnks,
    anila

    1.create a java file which is having one native function which calls the COM function.
    2.In static block put
    static{
    System.loadlibrary("WrapperDll");
    3.Compile the java file(example sample.java)
    4.Create the header file using the command
    javah -jni sample
    4.Create a wrapper dll in VC++.
    5.After creating wrapper dll in VC++ , keep the dll in the class path.
    6. Run the program
    See this link http://java.sun.com/docs/books/tutorial/native1.1/index.html
    Bye,
    nrs

  • IPC - write java routines or use RFCs

    This is more of a design question. I am new to IPC. We need to write really really huge pricing routines with a lot of hard coded values and case statements for CRM pricing in Java. One approach is to just do it in java. But the other approach is to write one small java routine and have it call an RFC in CRM and put all the calculation logic in that RFC. Since I don't know much about IPC, can some one please recommend which apporach would be more feasable based on your experience. What are the main performances issues you guys have faced for IPC.Can someone please share any experiences or "lessons learned for best practices" with me.
    Thanks
    Shahid

    remus.dragos wrote:
    Peter__Lawrey wrote:
    The simplest means of IPC in Java is using Sockets.
    However, you have mentioned JNI, but have considered calling the C code from the Web Service via JNI directly. This could be the simplest and most efficient.I agree on that, JNI is much more simplified when used from a web container. Although I used only
    Tomcat with JNI it was easy to use.However if it causes a system exception it will take down your tomcat server. And it is very difficult to debug.
    A socket solution has neither of those problems.

  • Can not deploy a report using JDBC connection on CR2008 Server

    Hi Group,
    I have a report created with JDBC connection. When I tried to add it to CR2008 server, it gives an error - "An unexpected error has occurred ". Basically I want to add a report to a public folder via CMC. I am using adminstrator account.
    Then I thought I need to add JDBC driver into CR2008 server. so I put oracle jdbc jar into CR2008 server classpath and add JDBC connection info into CRConfig.xml. but I still got the same error.
    I also tried:
    - Change the report to use native Oracle driver rather than JDBC. The deployment succeeded (but this is not what I want)
    - Add a data source connection via Business View Manager, but no luck.
    I know how to use/change jdbc connection with programtic way, but I just want to know if I want to use built-in components in CR2008 server without any coding the reports can be deployed and managed.
    Thanks in advance.
    Dennis

    Hello Will,
    Crystal Reports supports connections to JDBC/JNDI out of the box, and have done so for a while, whether stand-alone or published to Enterprise.
    To specify where the server would search for the JDBC driver jar files, you'd change the classpath tag found in the CRConfig.xml file found on the machine where the Crystal Reports Page or Job Server is running. 
    For early Crystal Enterprise 10 and before, it used Java Native Interface (JNI) to start the Java process to retrieve the data from the JDBC connection.
    For later Crystal Enterprise 10 and later, it starts off a "Java Server" process, and communicates to the Crystal Reports process via CORBA TCP/IP connection.
    Commonissues that may arise:  (1) CRConfig.xml not configured properly, (2) unable to start or communicate to the "Java Server" because of permissions or firewall.
    Note that this is a separate connectivity map from using ADO or ADO.NET.
    Sincerely,
    Ted Ueda

  • How to use dll function in JDeveloper?

    I want to use function in dll to develope my application,but
    I can't find how to do that in the JDeveloper document.
    null

    You have to use the Java Native Interface to use dlls. The JNI
    tutorial at http://java.sun.com/docs/books/tutorial/native1.1/
    walks you through the basics and provides a sample too.
    Hope this helps.
    Regards,
    yinjun (guest) wrote:
    : I want to use function in dll to develope my
    application,but
    : I can't find how to do that in the JDeveloper document.Who can
    : give me an answer? Thanks a lot in advance.
    null

  • How to Use DLL Function in Java Applet

    Hi all,
    I have been assigned a task to develop java applet. The problem is, I need to use DLL functions in my applet to read records. Could you pls anyone guide me how to interface DLL and applet to read records with sample code?
    I'm using JDK 1.5.0_06 and Windows XP OS. thanx..
    best rgds,
    jpdbay

    You will need to use Java Native Interface JNI. Ther are many posts on the subject, please search, and this is the documentation:
    http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html

  • Java interoperability solution to use C++,Python etc.

    I am working on a generic scripting/programming architecture for a Java application.
    There is a set of classes that I want to expose via API so that it can be used to developed plugins for interpreted languages. The final aim is to expose the Java classes as COM interfaces via a COM server or as Python packages etc. To achieve this I would have to use a form of RPC that is statefull. By statefull what I mean is that if a method in a Java class returns other Java object (non primitive) then that object should be available as proxy at the client side and it should not be passed by value. So any method invoked on the proxy object would result in a call to the actual Java object.
    Can someone comment on how I can achieve the above behavior? Which of these technologies could be used:
    JNI, XML-RPC, SOAP, CORBA etc.
    Are there any other useful options?
    Probably JNI could be used but its pretty complex and all the object reference handling would have to be done manually along with creation of proxy classes on the C++ side.
    I have looked at Jython, but its way behind the current Python versions.
    The idea is to develop a generic set of API so that plugins can be developed for any language on any platform. Any comments appreciated.

    Hey .. can someone help me here .. People have replied that CORBA would suite to my problem. I would like to know why. Its not that I am questioning the experts .. but I have to convince other developers working with me about it. Most of the developers working above me have heard of the recent (come one they are recent than Corba) buzzwords like SOAP, XML-RPC etc and would like me to use them. .. But I couldnt find of implementations based on SOAP/XML-RPC that would provide me a true RPC mechanism that I have described above. Please help me.
    Thanks.

  • How to use HTML parameters in Java applet

    Hello
    In perl I have created a form with things like a selectiuon box called currency and text fields called product for example. Then when I click submit the perl program can pick up the currency and product parameters.
    I have read about applet param eg <param name="param1" value="Apple"> is this the same thing? Or is it different?
    Can I use HTML parameters or do I need to use applet param? I am confused.
    If applet param is what I need, then how do I change the param values say by editing text in a text field?

    You will need to use Java Native Interface JNI. Ther are many posts on the subject, please search, and this is the documentation:
    http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html

Maybe you are looking for

  • Java\jdk1.6.0_02\jre\lib\ext\mysql-connector-java-5.1.16-bin.jar was unexp

    Hello, please i am new to Jdeveloper and weblogic servers and i developed an application using jdeveloper and when i try to run the application it brings up this error message "*** Using HTTP port 7101 *** *** Using SSL port 7102 *** C:\Users\Lucky\A

  • Passing custom field in contract in SRM to contract in ECC

    Hi, We are using SRM 7.0 with ECC 6 (no EHP). We're planning to use central contract distributed with IDOCs. Our contract in ECC has custom field added in the header. We have tried and successfully pass the contract from SRM to ECC (using IDOC BLAORD

  • Logical intervals on the x-axis

    Ok, this is what I'm trying to do: I'm trying to make a graph that shows dissolved oxygen content at different distances from the source of a river. the 'y' axis is working well, going up in a logical, 2 ppm intervals. But the x-axis - the one I'm us

  • How do I find the hardware specs? (iMAC, PowerMac G3 and PowerPC)

    For starters I have never used a mac before We have some iMACs, PowerMac G3s and PowerPCs in stock which have had their HDDs erased (zero'd) so there is no OS installed. I need to find the CPU type/speed & RAM size Is there a boot cd I can load to de

  • Software licence issues when upgrading to Leopard with a new machine

    Hi, This is a question about my licence for Logic, but also on a broader scale, all my plugins and AU instruments etc. of which I have bought many. I want to upgrade to Leopard (currently on Tiger 10.4.11), and realise that it's going to be a long an