Using dlls in java

can u help me in creating a java application that incorporates a dll created in visual basic or visual c++?

hey, throw your dukes ;-)
here's sample code for JACOB that shows you how easy it is:
import java.math.BigDecimal;
import java.util.*;
//jacob.jar:
import com.jacob.com.*;
import com.jacob.activeX.*;
* Test usage of Visual Basic DLLs in Java with JACOB (JAva-COM Bridge). Requires a DLL in the Java
* Lib Path with classes "TestProject.TestClass" and "TestProject.TestClass2" and the corresponding
* functions/subs.
* <p><b>Links:</b>
* <ul>
* <li><a href="http://danadler.com/jacob/">The JACOB Project: A JAva-COM Bridge</a>
* <li><a href="http://groups.yahoo.com/group/jacob-project/">Yahoo group: jacob-project</a>
* <li><a href="http://www.officecomputertraining.com/vbtutorial/tutpages/page32.asp">VB Dates and Time</a>
* </ul>
public class JacobTest {
     * Test application for JACOB.
     * @param args Not required.
    public static void main(String[] args) {
        System.out.println("Library path: "+System.getProperty("java.library.path"));
        ActiveXComponent activex = null;
        String dllClassName = "TestProject.TestClass";
        long time = System.currentTimeMillis();
        try {
            activex = new ActiveXComponent(dllClassName); //ProgId
            Object o = activex.getObject();
            Variant variant = null;
            System.out.println("\n*** Test function that returns a String:");
            variant = Dispatch.call(o, "getString", "Hello");
            System.out.println("getString('Hello'): "+variant.getString());
            List ml = new ArrayList();
            ml.add("mytest");
            System.out.println("\n*** Test function that returns a String:");
            variant = Dispatch.call(o, "getString", ml.get(0));
            System.out.println("getString('"+ml.get(0)+"'): "+variant.getString());
            System.out.println("\n*** Test function that returns an integer:");
            variant = Dispatch.call(o, "getInteger", new Integer(7));
            System.out.println("getInteger(7): "+variant.getShort());
            System.out.println("\n*** Test function that returns a double:");
            variant = Dispatch.call(o, "getDouble", new Double("12.34"));
            System.out.println("getDouble(12.34): "+variant.getDouble());
            System.out.println("\n*** Test function that returns a boolean:");
            variant = Dispatch.call(o, "getBoolean", new Boolean(true));
            System.out.println("getBoolean(true): "+variant.getBoolean());
            System.out.println("\n*** Test function that returns a date:");
            variant = Dispatch.call(o, "getDate");
            System.out.println("getDate(): "+variant.getDate());
            System.out.println("Java: "+new Date(toMilliseconds(variant.getDate())));
            System.out.println("\n*** Test function that returns a time:");
            variant = Dispatch.call(o, "getTime");
            System.out.println("getTime(): "+variant.getDate());
            System.out.println("Java: "+new Date(toMilliseconds(variant.getDate())));
            System.out.println("\n*** Test function that returns a timestamp:");
            variant = Dispatch.call(o, "getTimestamp");
            System.out.println("getTimestamp(): "+variant.getDate());
            System.out.println("Java: "+new Date(toMilliseconds(variant.getDate())));
            System.out.println("\n*** Test function that returns a timestamp:");
            variant = Dispatch.call(o, "getTimestamp");
            System.out.println("getTimestamp(): "+variant.getDate());
            System.out.println("Java: "+   new Date(toMilliseconds(variant.getDate())));
            System.out.println("\n*** Test function with optional parameter:");
            variant = Dispatch.call(o, "callOptionalParas", "eins", null, "drei");
            System.out.println("callOptionalParas(): "+variant.getString());
            System.out.println("\n*** Test function that returns a 2 dimensional array:");
            variant = Dispatch.call(o, "getArray", "*!*");
            SafeArray array = variant.toSafeArray(false);
            System.out.println("getArray('zwo'): "+array.getString(0,2));
            System.out.println("\n*** Test function with more than 8 parameters:");
            Object[] paras = new String[] {"1", "2", "3", "4", "five", "six", "seven", "eight", "nine", "ten"};
            variant = Dispatch.callN(o, "callNParas", paras);
            System.out.println("callNParas(..."+paras[9]+"): "+variant.getString());
            System.out.println("\n*** Test function that returns another COM object:");
            variant = Dispatch.call(o, "getTestClass2", "Test Object 1");
            Object class2 = variant.getDispatchRef();
            variant = Dispatch.call(class2, "getValue", "myPara!");
            System.out.println("getTestClass2().getValue('myPara'): "+variant);
//            System.out.println("\n*** Open a Microsoft Word document:");
//            ActiveXComponent oWord = new ActiveXComponent("Word.Application");
//            oWord.setProperty("Visible", new Variant(true));
//            Object oDocuments = oWord.getProperty("Documents").toDispatch();
//            Object oDocument = Dispatch.call(oDocuments, "Open", "E:/temp/TestDoc.doc").toDispatch();
//            Object oSelection = oWord.getProperty("Selection").toDispatch();
            System.out.println("\n*** Test function with new COM object parameter:");
            ActiveXComponent com2 = new ActiveXComponent("TestProject.TestClass2"); //ProgId
//            Dispatch d2 = (Dispatch) com2.getObject();
//            Variant v = new Variant(d2);
//            Dispatch vp = v.toDispatch();
            variant = Dispatch.call(o, "callWithComPara", com2);
            System.out.println("callWithComPara(): "+variant.getString());
            System.out.println("\nDuration [ms]: "+(System.currentTimeMillis() - time));
        } catch (Throwable t) {
            System.err.println("ERROR with ActiceX component '"+dllClassName+"': "+t);
    }//main()
     * Convert a Visual Basic time double value (e.g. from functions Date(), Time(), Now()) to a Java long value (milliseconds).
     * Visual Basic time values are based to 30.12.1899, Java time values are based to 1.1.1970 (= 0 milliseconds).
     * The difference is added to the Visual Basic value to get the corresponding Java value. The Visual Basic double value reads:
     * <day count delta since 30.12.1899>.<1 day percentage fraction>, e.g. "38100.6453" means: 38100 days since 30.12.1899
     * plus (24 hours * 0.6453). Example usage: <code>Date javaDate = new Date(toMilliseconds(vbDate));</code>.
     * @param vbTimestamp Time value from Visual Basic.
     * @return Number of milliseconds since 1.1.1970.
    static public long toMilliseconds(double vbTimestamp) {
        long result = 0;
        final long vbZeroTime = -2209165200000L; //30.12.1899 00:00:00 in milliseconds
        final long oneDay = 86400000; //1 day in milliseconds (24 * 60 * 60 * 1000)
        BigDecimal bd = new BigDecimal(""+vbTimestamp);
        long dayCount = bd.longValue(); //value left of point; number of days since 30.12.1899
        BigDecimal tp = bd.subtract(new BigDecimal(""+dayCount)); //fractional part is factor for 1 day (e.g. 0.5 => 12 hours)
        long date = vbZeroTime + (dayCount * oneDay); //compute java date
        //avoid problems with daylight savings time by setting time to 00:00:00 :
        GregorianCalendar dateCal = new GregorianCalendar();
        dateCal.setTimeInMillis(date);
        dateCal.set(Calendar.HOUR, 0);
        dateCal.set(Calendar.HOUR_OF_DAY, 0);
        dateCal.set(Calendar.MINUTE, 0);
        dateCal.set(Calendar.SECOND, 0);
        dateCal.set(Calendar.MILLISECOND, 0);
        date = dateCal.getTimeInMillis();
        long time = (long) (oneDay * tp.doubleValue()); //compute java time
        result = date + time;
        return result;
    }//toMilliseconds()
}//JacobTest()

Similar Messages

  • Using dll in Java with JNI

    Dear Friends.
    I have a dll which was developed in Visual Basic. If we use that in the VB code we can carry out certain methods.
    My concern is: I want to use this dll in my java method. what all the methods that can be used in the VB should also be used in java method.
    I know that this can be done using JNI, but please help me for getting starting, I am a bit new to this technology.
    thanks so much.
    Cheers,
    Lakshman

    Hi friends.
    I have checked up with all the forums in this site and more. the registered dll file is sucessfully loaded in the my java file. i complied it and got my .h file...
    until this point, i got everything correct. in all the articles i read, they have given an implementation in C/C++ fo the methods declared by including the header file.
    but as per my requirement, i dont have my own implementations for any methods. I already have some methods in the dll which i want to call from the java program.
    please give me your views on this..
    thanks.
    Lakshman Pilaka.

  • Use DLLs with Java

    Hello!
    I want to use Code implemented in a C++ DLL.
    Should I just use JNI?
    I have heared that there are some nice "tools"
    like Centro that are making it easier to use the
    DLLs.
    What do you think? What are your experiences?
    Thanks

    Using JNI, u can implement.

  • How to use .dll compiled in Delphi in Java?

    Can anyone provide me information how to use .dll compiled in Delphi in Java? The .dll Delphi program may be non-OOP program.

    Hi
    If You want to write anything in PASCAL then simply write JNI code in C++ and call functions from this DELPHI DLL, but remember about changing the order of parameters etc when You call it. I had exactly the same problem, but it is possible, and we succeed.
    You will need exact description of input parameters required by PASCAL functions and of output parameters. Then construct in C++ objects wchich looks in memory exacly the same as they will look if You will be using PASCAL. Then PASCAL function will interprete this area in memory as known structure and will run.
    Maciek

  • 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

  • How to use the Rc4DLL.dll with java (jre1.4 )

    I am not able to use Rc4DLL.dll with java, there are some characters (encrypted using Rc4DLL.dll) that java is not able to identify. So while decrypting in java using Rc4DLL I am not getting the desired output (as some character java tries to decrypt are not supported with java). Could some one give a solution of using Rc4DLL with java jre 1.4

    RC4 cipher is supported by 1.4.
    And surely you can turn a link to the 1.5.0 JCE Reference Guide into a link to the 1.4.2 Reference Guide? I did. Took me 5 seconds to check that. As opposed to wasting a day and a half in forums like you just did.

  • Calling dll in Java using The JACOB Project

    Hi I'm trying to import and read the class and methods from a DotNet API (dll) in java code usind the Jacon Project does anybody know how to do it? (like and example or simple staps to have an idea)
    thanks
    Luca

    afaik you cannot call windows API functions directly, you have to create a 'wrapper' method in C++ in order to access the API functions.
    it will look something like
    // Java code:
    package a.b;
    class Thingie {
      public native int doThatFunkyThingie();
    // c++ code
    jint Java_a_b_Thingie_doThatFunkyThingie(JNIEnv *env, JObject j) {
      // c++ function calls go here
    }I haven't done JNI in over a year, so this is probably not entirely correct.
    I recommend you read the JNI tutorial.
    J

  • How to call VB dlls in java

    Hi
    I created one component in vb, where this component got 3 methods. and created dll also, when iam trying to use these dlls in java. it showing error, is there any method to call the vb dlls in java(native method), if s pls help me to solve these problem.

    hi, all
    I writed a vb dll, It have three publice sub and one preporty,
    I use html <object> attribute to declare this dll and call its methods and perporty in html file, everything is ok.the source code as following:
    <body>
    <OBJECT declare id="repExport" classid="clsid:0487D845-0DAD-46D0-9559-FADEC117C2B9">
    <param name="Exportfile" value="peiru">
    </OBJECT>
    <script language="vbscript">
    repExport.Exportfile="peiruyt"
    repExport.CrystalConnect()
    repExport.PassParameterRtp()
    repExport.reportexport()
    </script>
    Because i need get parameter from other web page , and i use weblogic 6.1 server, so i need change file type from html to jsp , But even if I just change the file extension from html to jsp, don't change any content in this file.
    then jsp cannot work, error message is "object don't support 'repExport.Exportfile' property", actual it don't support all three functions and a property
    Can anyone provide any help?
    thanks
    peiru

  • 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

  • Calling DLLs in JAVA

    Hi,
    I need to create a utility for a component in a 3rd party tool. I am planning to create this utility in JAVA. But the problem is that the 3rd party tool uses DLLs which is created in VB 6.0 (Its seems so).
    I came across the key word "NATIVE" in JDK. But the examples related to this is all given for C/C++. I am not sure whether following the same procedure we will be able to access any VB dlls.
    Please help me out. I am aware that there are ceratin APIs which we can use as a Bridge between Dlls and Java. And If I am right one among such is JACOB. But I am trying to minimize the dependencies of my Java Code to any other Utilities.
    Eagerly waiting for a valuable Advice
    Jiju Jagadish

    Hi,
    It seems you'll need to compile you own DLL wrapper if you do not want to depend on 3rd party library, search for JNI spec here.
    On the other hand generic wrappers save time, if you are not famillar with C/C++.
    Look at that post : http://forum.java.sun.com/thread.jspa?threadID=722211&tstart=0
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Possible to make a dll with java?

    I am completely new to Java. Is it possible to create a Windows style DLL with Java? I am working with one project written in VB.NET which needs to access functions in another project written in Java. Can anybody help me figure out how to do this?

    I'm not sure what you mean by what type of project. It contains numerous data analysis functions which I want to access from a VB.NET program. From what you've written, I must assume that Java cannot be used to create a DLL and my only option is to rewrite it in another language. Thank you for the info.

  • Calling back c++ method in an exe (not a dll) from java?

    Hi all,
    I have to make an hybrid C++/java from an existing C++
    application that compiled is a big single exe not a dll.
    I'm running under win32.
    The application consists of several windows. The hybrid
    will have widows in C++ and some in java. They have the
    same menu and tool bar. In the C++, there are some
    callbacks called when a button is pressed. How to call
    these callback from java given the fact that the JVM and
    the java classes are launched by the exe file.
    I know how, from C++, start JVM and call my java window.
    I also know how to call a C++ method that is in a dll from
    java. It's from the tutorial
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    But I don't know how to call a C++ method that is in in an
    exe which has launch a JVM from an object running in this
    JVM.
    Is there somewhere an example like this?
    Thanks,
    Xavier.

    Thanks this helped.
    For those who want a complete example, here it is:
    Tested on XP, java 1.4.2, VC++ 6.0.
    ************ File invoke.cpp *****************************
    #include <stdlib.h>
    #include <jni.h>
    #ifdef _WIN32
    #define PATH_SEPARATOR ';'
    #else /* UNIX */
    #define PATH_SEPARATOR ':'
    #endif
    #define USER_CLASSPATH "." /* where Prog.class is */
    void JNICALL displayHelloWorld(JNIEnv *env, jobject obj)
        printf("Hello world: made by printf from C++\n");
        return;
    void main() {
        JNIEnv *env;
        JavaVM *jvm;
        JavaVMInitArgs vm_args;
        jint res;
        jclass cls;
        jmethodID mid;
        jstring jstr;
        jobjectArray args;
        char classpath[1024];
         int result;
        /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
         JavaVMOption options[3];
         options[0].optionString = "-verbose:gc";
         sprintf (classpath, "-Djava.class.path=%s", USER_CLASSPATH);
         options[1].optionString = classpath;
         options[2].optionString = "-Djava.compiler=NONE";
         vm_args.options = options;
         vm_args.nOptions = 3;
         vm_args.ignoreUnrecognized = JNI_TRUE;
            vm_args.version = JNI_VERSION_1_4;
         /* IMPORTANT: Note that in the Java 2 SDK, there is no longer any need to call
          * JNI_GetDefaultJavaVMInitArgs. It causes a bug
        /* Append USER_CLASSPATH to the end of default system class path */
        /* Create the Java VM */
        res = JNI_CreateJavaVM(&jvm,(void**)&env, &vm_args);
        if (res < 0) {
            fprintf(stderr, "Can't create Java VM\n");
            exit(1);
        cls = env->FindClass("mypackage/Prog");
        if (cls == 0) {
            fprintf(stderr, "Can't find mypackage/Prog class\n");
            exit(1);
       JNINativeMethod nm;
       nm.name = "displayHelloWorld";
       /* method descriptor assigned to signature field */
       nm.signature = "()V";
       nm.fnPtr = displayHelloWorld;
       env->RegisterNatives(cls, &nm, 1);
        mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
        if (mid == 0) {
            fprintf(stderr, "Can't find Prog.main\n");
            exit(1);
        jstr = env->NewStringUTF(" from C++! calleded by C++, using argument from C++ but java method");
        if (jstr == 0) {
            fprintf(stderr, "Out of memory\n");
            exit(1);
        args = env->NewObjectArray(1,
                            env->FindClass("java/lang/String"), jstr);
        if (args == 0) {
            fprintf(stderr, "Out of memory\n");
            exit(1);
        env->CallStaticVoidMethod(cls, mid, args);
        jvm->DestroyJavaVM();
    }********************* File ./mypackage/Prog.java **************************
    package mypackage;
    public class Prog {
           public native void displayHelloWorld();
        public static void main(String[] args) {
            System.out.println("Hello World" + args[0] +"\n");
            Prog prog = new Prog();
            prog.displayHelloWorld();
            System.out.println("(called from java)");
            System.out.println("\nSo to sumurize:");
            System.out.println(" -1 Starting point is an exe (not DLL, there is no DLL) so C++ code");
            System.out.println(" -2 From C++ call java method using argument from C++");
            System.out.println(" -3 From java, that was launched by the exe, call to");
            System.out.println("    a native using the RegisterNatives in C++\n");
            System.out.println("You got a bidirectional example with as starting point");
            System.out.println("a single exe, launching JVM, loading class call back C++!");
    }******************* Command line for all ****************************************
    javac mypackage/Prog
    cl -I"D:\Program Files\j2sdk1.4.2_03\include" -I"D:\Program Files\j2sdk1.4.2_03\include\win32" -MT
    invoke.cpp -link D:\PROGRA~1\j2sdk1.4.2_03\lib\jvm.lib
    (Remark, the last path is using the short name for "Program Files" because with the blank
    even adding double quotes result into an error)
    You must have jvm.dll in your path for me it's Path=D:\Program Files\j2sdk1.4.2_03\jre\bin\client;
    Then simply call invoke and see the result. :-)

  • Invoking Native Dll in Java

    Hi,
    We have tried to invoke a native dll method using JNI in java.
    While invoking the dll method(below native code dll) we face the "Access violation error".
    But the very same native implementation code is working successfully when invoked from VC++ Exe application.
    We have given the Java class file, header file, CPP implementation of the method and the error report below.
    Can anybody let us know if there is some fault in the way code we have coded?
    *{color:#0000ff}Source Code:{color}
    {color:#0000ff}---------------------{color}
    _______________________________________WsqLib.java____________________________________________________________________
    class WsqLib
    private native int BitmapToWSQ();
    private native int WsqToBitmap();
    public static void main(String[] args)
    WsqLib wsqlib=new WsqLib();
    System.out.println("wsqlib.BitmapToWSQ() ==> "+wsqlib.BitmapToWSQ());
    static
    System.loadLibrary("WsqLib");
    # Create a class (WsqLib.java) that declares the native method.
    # We use javac to compile the WsqLib source file, resulting in the class file WsqLib.class.
    # We use javah to generate a C header file (WsqLib.h) containing the function prototype for the native method implementation.*
    _______________________________________WsqLib.h*_______________________________________________________________________
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include "jni.h"
    /* Header for class WsqLib */
    #ifndef IncludedWsqLib
    #define IncludedWsqLib
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: WsqLib
    * Method: BitmapToWSQ
    * Signature: ()I
    JNIEXPORT jint JNICALL Java_WsqLib_BitmapToWSQ
    (JNIEnv *, jobject);
    * Class: WsqLib
    * Method: WsqToBitmap
    * Signature: ()I
    JNIEXPORT jint JNICALL Java_WsqLib_WsqToBitmap
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    # CPP implementation (WsqLib.cpp) of the native method is as below.
    # We compiled the cpp implementation into a native library, creating WsqLib.dll.
    # We use the WsqLib.dll in WsqLib.java.
    _______________________________________WsqLib.cpp______________________________________________________________________
    #include "stdafx.h"
    #include "WsqLib.h"
    #include "_vcclrit.h"
    #include "gdiplus.h"
    #include <afxstr.h>
    #include <atlimage.h>
    #include "WsqLib1.h"
    static const GUID guidBmp =
    { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e } };
    extern "C"
    int debug = 0;
    JNIEXPORT jint JNICALL Java_WsqLib_BitmapToWSQ(JNIEnv *, jobject)
    Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromFile(L"temp.bmp", TRUE);
    Gdiplus::BitmapData lockedBitmapData;
    Gdiplus::Rect rect(0, 0,pBitmap->GetWidth(),pBitmap->GetHeight());
    //Error occured in this Line.
    pBitmap->LockBits( &rect, Gdiplus::ImageLockModeRead, PixelFormat8bppIndexed, &lockedBitmapData );
    int byteCount = pBitmap->GetWidth() * pBitmap->GetHeight() * (int)(8 / 8);
    unsigned char *pPixelData2 = new unsigned char[byteCount];
    memset(pPixelData2, 0, (size_t)byteCount);
    unsigned char pBytes = (unsigned char) lockedBitmapData.Scan0;
    for (int index = 0; index < byteCount; index++)
    pPixelData2[index] = pBytes[index];
    pBitmap->UnlockBits(&lockedBitmapData);
    unsigned char *pPixelData = pPixelData2;
    int pixelsPerInch = (int)pBitmap->GetHorizontalResolution();
    float compressionFactor = (float)( (float)((int)75) / 100.0);
    unsigned char *pWsqBytes = NULL;
    int wsqBytesCount = 0;
    int result = 0;
    result = wsq_encode_mem(
    &pWsqBytes, // Output data buffer
    &wsqBytesCount, // Length of output data buffer
    compressionFactor, // Determines the amount of lossy compression.
    pPixelData, // Input pixel data
    pBitmap->GetWidth(), // Pixel width of the pixmap
    pBitmap->GetHeight(), // Pixel height of the pixmap
    8, // Depth (bits) of the pixmap
    pixelsPerInch, // Scan resolution of the image in integer units of pixels per inch
    (char *)NULL // Optional (we do not want to use this - we may even want to remove the implementation)
    if (result == 0)
    FILE *fptr1;
    fptr1=fopen("C:\\saran2.wsq_1.0","wb");
    fwrite(pWsqBytes,wsqBytesCount,1,fptr1);
    fclose(fptr1);
    return 10;
    JNIEXPORT jint JNICALL Java_WsqLib_WsqToBitmap(JNIEnv *, jobject)
    BYTE gData[242998];
    Gdiplus::Bitmap* image;
    CFile file;
    file.Open("temp.wsq_1.0",CFile::modeRead,NULL);
    file.Read(gData,242998);
    unsigned char pByteArray =(unsigned char)gData;
    unsigned char *pPixelData = NULL;
    int bitmapWidth = 0;
    int bitmapHeight = 0;
    int pixelDepth = 0;
    int pixelsPerInch = 0;
    int lossyFlag = 1;
    int byteArrayLength = 242998;
    int result = 0;
    result = wsq_decode_mem(
    &pPixelData, // Output image buffer
    &bitmapWidth, // Pixel width of the pixmap
    &bitmapHeight, // Pixel height of the pixmap
    &pixelDepth, // Depth (bits) of the pixmap
    &pixelsPerInch, // Scan resolution of the image in integer units of pixels per inch
    &lossyFlag, // Is the image lossy? F.I.I.K.
    pByteArray, // Input data buffer
    byteArrayLength // Input data buffer length
    if (result == 0 && pixelDepth == 8)
    image = new Gdiplus::Bitmap(bitmapWidth, bitmapHeight);
    Gdiplus::Rect bound( 0, 0,bitmapWidth,bitmapHeight);
    Gdiplus::BitmapData lockedBitmapData;
    image->LockBits( &bound, Gdiplus::ImageLockModeWrite, PixelFormat8bppIndexed, &lockedBitmapData );
    int imageRowSize = bitmapWidth * (8/8);
    unsigned char pBitmapPixelData = (unsigned char )lockedBitmapData.Scan0;
    int byteCount = bitmapWidth * bitmapHeight;
    for (int index = 0; index < byteCount; index++)
    pBitmapPixelData[index] = pPixelData[index];
    image->UnlockBits( &lockedBitmapData );
    else
    return result;
    image->Save(L"C:\\temp.bmp", &guidBmp);
    return 0;
    {color:#0000ff}Error report:{color}
    {color:#0000ff}-------------------{color}
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x03920780, pid=380, tid=3572
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_12-b04 mixed mode, sharing)
    # Problematic frame:
    # C 0x03920780
    --------------- T H R E A D ---------------
    Current thread (0x00036d88): JavaThread "main" [_thread_in_native, id=3572]
    siginfo: ExceptionCode=0xc0000005, reading address 0x00000004
    Registers:
    EAX=0x00000000, EBX=0x00000000, ECX=0x00000000, EDX=0x00000000
    ESP=0x0007f9a8, EBP=0x0007fa70, ESI=0x00000000, EDI=0x00000000
    EIP=0x03920780, EFLAGS=0x00010246
    Top of Stack: (sp=0x0007f9a8)
    0x0007f9a8: 00000000 00000000 00000000 00000000
    0x0007f9b8: 039204ba 00000001 00000000 000be780
    0x0007f9c8: 03726248 0007fa10 00000000 00000000
    0x0007f9d8: 03920430 0007fa2c 7a32b4fa ffffffff
    0x0007f9e8: 0007fa38 79e7bba9 79e7bbb1 cce41966
    0x0007f9f8: ffffffff 0007fa68 000a4b30 00000000
    0x0007fa08: 00000000 00000000 00000000 00000000
    0x0007fa18: 00000000 00000000 00000000 00000000
    Instructions: (pc=0x03920780)
    0x03920770: 03 00 74 05 e8 85 1b 77 76 33 d2 89 14 24 8b fe
    0x03920780: 8b 4e 04 8d 14 24 e8 05 65 e0 ff 8b d8 8b d3 8b
    Stack: [0x00040000,0x00080000), sp=0x0007f9a8, free space=254k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C 0x03920780
    C 0x031e3171
    j WsqLib.BitmapToWSQ()I+0
    j WsqLib.main([Ljava/lang/String;)V+24
    v ~StubRoutines::call_stub
    V [jvm.dll+0x87599]
    V [jvm.dll+0xdfbb2]
    V [jvm.dll+0x8746a]
    V [jvm.dll+0x8e6ac]
    C [java.exe+0x14c5]
    C [java.exe+0x69cd]
    C [kernel32.dll+0x16d4f]
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j WsqLib.BitmapToWSQ()I+0
    j WsqLib.main([Ljava/lang/String;)V+24
    v ~StubRoutines::call_stub
    --------------- P R O C E S S ---------------
    Java Threads: ( => current thread )
    0x009f2b28 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3996]
    0x009f1820 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2832]
    0x009f0a68 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=404]
    0x009eb330 JavaThread "Finalizer" daemon [_thread_blocked, id=3304]
    0x009e9eb0 JavaThread "Reference Handler" daemon [_thread_blocked, id=1648]
    =>0x00036d88 JavaThread "main" [_thread_in_native, id=3572]
    Other Threads:
    0x009c8508 VMThread [id=492]
    0x009f0528 WatcherThread [id=2924]
    VM state:not at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: None
    Heap
    def new generation total 576K, used 497K [0x22a50000, 0x22af0000, 0x22f30000)
    eden space 512K, 84% used [0x22a50000, 0x22abc5b8, 0x22ad0000)
    from space 64K, 99% used [0x22ae0000, 0x22aefff8, 0x22af0000)
    to space 64K, 0% used [0x22ad0000, 0x22ad0000, 0x22ae0000)
    tenured generation total 1408K, used 115K [0x22f30000, 0x23090000, 0x26a50000)
    the space 1408K, 8% used [0x22f30000, 0x22f4cc28, 0x22f4ce00, 0x23090000)
    compacting perm gen total 8192K, used 20K [0x26a50000, 0x27250000, 0x2aa50000)
    the space 8192K, 0% used [0x26a50000, 0x26a553b8, 0x26a55400, 0x27250000)
    ro space 8192K, 63% used [0x2aa50000, 0x2af60590, 0x2af60600, 0x2b250000)
    rw space 12288K, 46% used [0x2b250000, 0x2b7f21b0, 0x2b7f2200, 0x2be50000)
    Dynamic libraries:
    0x00400000 - 0x0040d000 C:\WINDOWS\system32\java.exe
    0x7c900000 - 0x7c9b0000 C:\WINDOWS\system32\ntdll.dll
    0x7c800000 - 0x7c8f4000 C:\WINDOWS\system32\kernel32.dll
    0x77dd0000 - 0x77e6b000 C:\WINDOWS\system32\ADVAPI32.dll
    0x77e70000 - 0x77f01000 C:\WINDOWS\system32\RPCRT4.dll
    0x77c10000 - 0x77c68000 C:\WINDOWS\system32\MSVCRT.dll
    0x6d640000 - 0x6d7dd000 C:\Program Files\Java\jre1.5.0_12\bin\client\jvm.dll
    0x77d40000 - 0x77dd0000 C:\WINDOWS\system32\USER32.dll
    0x77f10000 - 0x77f56000 C:\WINDOWS\system32\GDI32.dll
    0x76b40000 - 0x76b6d000 C:\WINDOWS\system32\WINMM.dll
    0x6d290000 - 0x6d298000 C:\Program Files\Java\jre1.5.0_12\bin\hpi.dll
    0x76bf0000 - 0x76bfb000 C:\WINDOWS\system32\PSAPI.DLL
    0x6d610000 - 0x6d61c000 C:\Program Files\Java\jre1.5.0_12\bin\verify.dll
    0x6d310000 - 0x6d32d000 C:\Program Files\Java\jre1.5.0_12\bin\java.dll
    0x6d630000 - 0x6d63f000 C:\Program Files\Java\jre1.5.0_12\bin\zip.dll
    0x10000000 - 0x10075000 D:\Jagadeesan\JNI_NEW\WSQ\WsqLib.dll
    0x79000000 - 0x79045000 C:\WINDOWS\system32\mscoree.dll
    0x7c140000 - 0x7c357000 C:\WINDOWS\system32\MFC71D.DLL
    0x10200000 - 0x10287000 C:\WINDOWS\system32\MSVCR71D.dll
    0x77f60000 - 0x77fd6000 C:\WINDOWS\system32\SHLWAPI.dll
    0x77120000 - 0x771ac000 C:\WINDOWS\system32\OLEAUT32.dll
    0x774e0000 - 0x7761c000 C:\WINDOWS\system32\ole32.dll
    0x4ec50000 - 0x4edf3000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.2180_x-ww_522f9f82\gdiplus.dll
    0x5d360000 - 0x5d36e000 C:\WINDOWS\system32\MFC71ENU.DLL
    0x79e70000 - 0x7a3d1000 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
    0x78130000 - 0x781cb000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\MSVCR80.dll
    0x7c9c0000 - 0x7d1d4000 C:\WINDOWS\system32\shell32.dll
    0x773d0000 - 0x774d2000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
    0x5d090000 - 0x5d127000 C:\WINDOWS\system32\comctl32.dll
    0x790c0000 - 0x79ba6000 C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\bf3b003e3ac7e449bdf8fc9375318452\mscorlib.ni.dll
    0x79060000 - 0x790b3000 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
    0x5e380000 - 0x5e409000 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll
    VM Arguments:
    java_command: WsqLib
    Launcher Type: SUN_STANDARD
    Environment Variables:
    JAVA_HOME=C:\Program Files\Java\jdk1.5.0_12;
    CLASSPATH=C:\Program Files\Apache Software Foundation\Tomcat 5.5\shared\lib\*.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\org\apache\axis\transport\http\*.classs;D:\JONAS_4_6_6\lib\ext\axis.jar;C:\Sun\jwsdp-1.6\jaxp\lib\endorsed\sax.jar;C:\tomcat50-jwsdp\jaxp\lib\endorsed\sax.jar;C:\Files\Java\jdk1.5.0_01\jre\lib;C:\Program Files\Java\jdk1.5.0_12\jre\lib\ext;
    PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D:\Jagadeesan Backup\DotNet\DynamicLibrary\MathFuncsDll\Debug;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies;C:\Sun\jwsdp-1.6\jaxrpc\bin;C:\Sun\jwsdp-1.6\jaxp\lib;C:\Sun\jwsdp-1.6\jaxp\lib\endorsed;C:\Program Files\Java\jdk1.5.0_12\bin;C:\Sun\jwsdp-1.6\jwsdp-shared\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Sun\jwsdp-1.6\jaxrpc\bin;C:\Sun\jwsdp-1.6\jaxp\lib;C:\Sun\jwsdp-1.6\jaxp\lib\endorsed;C:\Program Files\Java\jdk1.5.0_12\bin;
    USERNAME=Administrator
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=x86 Family 15 Model 1 Stepping 2, GenuineIntel
    --------------- S Y S T E M ---------------
    OS: Windows XP Build 2600 Service Pack 2
    CPU:total 1 (cores per cpu 1, threads per core 1) family 15 model 1 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2
    Memory: 4k page, physical 259888k(81380k free), swap 636388k(342588k free)
    vm_info: Java HotSpot(TM) Client VM (1.5.0_12-b04) for windows-x86, built on May 2 2007 02:07:59 by "java_re" with MS VC++ 6.0

    Is there any other reason for this error?There is one and only one reason for the error code 0xc0000005 - there is a pointer (C/C++) pointing somewhere it shouldn't.
    The above C code working fine while invoking in VC++ Exe application,
    But the error occured only while invoking in java using JNI.Which suggests only that sometimes that it works. It doesn't mean that it always works.
    There are a number of places in the C/C++ code where it could fail and none of them are being checked.

  • Exception thrown while using JCo in Java agents  in Lotus Domino applns.

    I am trying to use JCo in Java agents in a lotus domino application.  Here is my code:(This Java agent calls a Remote enabled function module in SAP which gives the sum of two given numbers)
    import lotus.domino.*;
    import java.util.*;
    import java.io.*;
    import com.sap.mw.jco.*;
    public class JavaAgent extends AgentBase
    private static JCO.Client jClient;
    public JCO.Client getJCOClient(String poolName) throws IOException, JCO.Exception
           System.out.println("Inside getJCOClient method");          
           System.out.println("Pool Name : "+ poolName);  
              boolean poolExists = false;     
          JCO.PoolManager poolManager  = JCO.PoolManager.singleton();
           String poolNames[] = poolManager.getPoolNames();
          // To check whether the given pool name already exists     
         if(poolNames != null)
                for(int poolIter = 0;poolIter<poolNames.length;poolIter++)
                 if(poolNames[poolIter].equals(poolName))
                        System.out.println("POOL ID =====>> "+poolName);
                        System.out.println("POOL NAMES["+ poolIter "] ========>>"poolNames[poolIter]);
                        poolExists = true;
                        break;
         String s = String.valueOf( poolExists );
          System.out.println("pool Exists :" + s );     
          if(poolExists == false)
               try
                   int maxConnections = 50;
                   String JCOClient = "111";
                   String user = "apabap4";
                   String password = "sap123";
                   String language = "en";
                   String ashost = "172.25.10.68";
                   String sysnr = "00";
                   //To create an instance of a client pool to the remote SAP system
                   System.out.println("Before addClientPool");
                   System.out.println("Pool Name : " + poolName);
                   JCO.addClientPool(poolName,maxConnections,JCOClient,user,password,language,ashost,sysnr);
              //     JCO.createClient(JCOClient, user,password,language, "172.25.10.68");
                   System.out.println("New Connection Pool Created");
               catch(JCO.Exception jcoe)
                    throw new JCO.Exception(jcoe.getGroup(),jcoe.getKey(),"Error in client pool creation "+jcoe.toString());
         try
                  //getClient() method returns a client connection from the specified spool     
                   jClient = JCO.getClient(poolName);
         catch(JCO.Exception jcoe1)
                   throw new JCO.Exception(jcoe1.getGroup(),jcoe1.getKey(),"Error in getting JCO client "+jcoe1.toString());
              return jClient;
         // End of method getJCOClient()     
         public void releaseJCOClient() throws JCO.Exception
          try
                   JCO.releaseClient(jClient);
         catch(JCO.Exception jcoe2)
                   throw new JCO.Exception(jcoe2.getGroup(),jcoe2.getKey(),"Error in releasing client "+jcoe2.toString());
    public void NotesMain()
              try {
                   Session session = getSession();
                   AgentContext agentContext = session.getAgentContext();
                  Document doc = agentContext.getDocumentContext();
       JavaAgent jcoObj = new JavaAgent();
       JCO.Client jClient = null;
       String poolId = new String("EG_POOL");
       IFunctionTemplate   ifun;//For function object
       JCO.Function func;          
       JCO.ParameterList importParams,exportParams,tableParams;
       try{
             jClient = jcoObj.getJCOClient(poolId);
           System.out.println("After Getting Connection");
           System.out.println("Attributes:" + jClient.getAttributes());
            //Create a repository object
            JCO.Repository mRepository = new JCO.Repository("myJCO_REPOSITORY", jClient);
            //Creating a function object
            ifun = mRepository.getFunctionTemplate("ZSUM");// The Function Name
           func = ifun.getFunction();
            System.out.println("Function name " + func.getName());
            //To get the import parameters in the function module
            importParams = func.getImportParameterList();
            System.out.println("Import parameters"+ importParams);
            importParams.appendValue("OPERAND1",importParams.TYPE_INT,4,"25");
           importParams.appendValue("OPERAND2",importParams.TYPE_INT,4,"25");
            jClient.execute(func);//Executing the function 
            //To get the export parameters in the function module
            exportParams = func.getExportParameterList();
               System.out.println("Export parameters" + exportParams);
            int sumVl = exportParams.getInt("SUM");
            Integer sumValue = new Integer(sumVl);
            System.out.println("Sum Value" + sumValue);
             doc.replaceItemValue("txtSum", sumValue.toString());
            //releaseJCOClient();
      catch(IOException ioe)
          ioe.printStackTrace();
      catch(JCO.Exception jcoe1)
          jcoe1.printStackTrace();
              } catch(Exception e) {
                   e.printStackTrace();
    While executing this agent I am getting the following exception.
    08/25/2004 06:27:45 PM  HTTP JVM: java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'  Native Library C:\Lotus\Domino\sapjcorfc.dll already loaded in another classloader
    08/25/2004 06:27:45 PM  HTTP JVM:  at com.sap.mw.jco.JCO.<clinit>(Unknown Source)
    08/25/2004 06:27:45 PM  HTTP JVM:  at JCoCallTrans.getJCOClient(JCoCallTrans.java:42)
    08/25/2004 06:27:45 PM  HTTP JVM:  at JCoCallTrans.NotesMain(JCoCallTrans.java:88)
    08/25/2004 06:27:45 PM  HTTP JVM:  at lotus.domino.AgentBase.runNotes(Unknown Source)
    08/25/2004 06:27:45 PM  HTTP JVM:  at lotus.domino.NotesThread.run(NotesThread.java:208)
    08/25/2004 06:27:45 PM  HTTP JVM: Error cleaning up agent threads
    Also I have placed the jco.jar in lib of jvm in Domino directory i.e.,
    Lotus\Domino\jvm\lib and
    sapjcorfc.dll and librfc32.dll in system32 of WINNT folder.
    Kindly help me to rectify this problem
    Arokiaraj.S

    I had approximate the same problem, and I've fixed it. In my jar file the javaHelpSearch Folder was named with a leading lower case "j". But in my helpset.hs it was with an upper Case "J"
    <name>Search</name>
        <label>Search</label>
        <type>javax.help.SearchView</type>
        <data engine="com.sun.java.help.search.DefaultSearchEngine">JavaHelpSearch</data>
       </view>When the helpset is called from a folder: windows ignore it, but when the helpset is called from into a jar you must type it correct!

  • Dll for java help...

    I 'd like to create a specific dll usable by java and i just have one dll not usable with java.
    i need your help if you know a routine, program .. that create automatically my dll for my java use.

    So im'going to be clear for people of all the world
    I'm working on a project in which i have to communicate with an video acquire board. I must retrieve video signal send by the camera to the video acquire board.
    Video acquire board constructor gives me a dll and a lib with functions but has not anticipated that maybe somebody will use a java program (Bad for me to be polite...)
    My problem is to call the methods of the constructor dll in java .I must use jni to generate a specific dll undertsood by java (dll containing a c and a h file with JNIEXPORT syntax.)
    But the constructor dll is not correctly written by the constructor to be interpreted by java.
    So the dll i must generate has to communicate with constructor dll and there, it is the dark side...
    Can you help me or have i lost you?

Maybe you are looking for