VB TO JAVA - STRING CONCATENATION


AIM:
    To create a VB to Java application for the implementation of string concatenation.

ALGORITHM:

Step 1: Start
Step 2: Code the concat function
Step 3: Save the project as VBTestLib.vbp and class as CTest.cls
Step 4: Make VBTestDLL.dll file
Step 5: Code the Java program and save it as JTest.java
Step 6: Compile the Java program and create the header file JTest.h using Java Native Interface
Step 7: Open Visual C++ 6.0 & select New  MFC Application(dll) and Name the project as ‘VBtoJava’ and save the project
Step 8: Include the header files JTest.h, jni.h, jni_md.h to the project
Step 9: Code at end of file in StdAfx.h and VBtoJava.cpp
Step 10: Build the application
Step 11: Copy & Paste the file VBtoJava.dll file from debug folder to VBtoJava folder
Step 12: Run the JTest.java program
Step 13:Stop

SOURCE CODE:

VBTestLib.vbp
public  function vbconcat(ByVal a As String,ByVal b As String) As String
vbconcat = a & b

End Function

JTest.java
import java.io.*;
public class JTest
{

         public static native String vbconcat(String s1,String s2);
         static
          {
    System.loadLibrary("VBtoJAVA");
          }
         public static void main(String args[])
         {
        try
         {
       String a,b;
       DataInputStream o=new DataInputStream(System.in);
       System.out.println("Enter the 1st string:");
       a=o.readLine();
       System.out.println("Enter the 2nd string:");
       b=o.readLine();
       System.out.println("\nConcatenated String is "+vbconcat(a,b));
         }
        catch(Exception e)
         {
        System.out.println("Exception"+e);
         }
    }

}

StdAfx.h
#include "JTest.h"
#include "jni.h"
#import "D:\Jebastin\VBtoJAVA\VBTestDLL.dll"
using namespace VBTestLib;

VBtoJAVA.cpp
#include "StdAfx.h"
#include "VBtoJAVA.h"
JNIEXPORT jstring JNICALL Java_JTest_vbconcat(JNIEnv *env,jclass jc,jstring a,jstring b)
{
    HRESULT hresult;
    CLSID clsid;
    _CTest *t;
    jboolean blnIsCopy;
    jstring jstrOut;
    _bstr_t bstrA;
    _bstr_t bstrB;
    _bstr_t bstrR;
    char *strR;
    const char *strA=(env)->GetStringUTFChars(a,&blnIsCopy);
    const char *strB=(env)->GetStringUTFChars(b,&blnIsCopy);
    bstrA=(_bstr_t)strA;
    bstrB=(_bstr_t)strB;
    ::CoInitialize(NULL);
    hresult=CLSIDFromProgID(OLESTR("VBTestLib.CTest"),&clsid);
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,_uuidof
 (_CTest),(LPVOID*)&t);
    if(hresult==S_OK)
    {
        bstrR=t->vbconcat(bstrA,bstrB);
        strR=(char*)bstrR;
        jstrOut=(env)->NewStringUTF(strR);
    }
    else
    {
        jstrOut=(env)->NewStringUTF("error");
    }
    (env)->ReleaseStringUTFChars(a,strA);
    (env)->ReleaseStringUTFChars(b,strB);
    return jstrOut;
}

OUTPUT:

 
RESULT:
          Thus the VB to Java application for string concatenation was performed and the output was verified.

.
Previous
Next Post »

Still not found what you are looking for? Try again here.