how to create DLL file in J# or convert J++ dll into J# dll

Please help me...I know nothing about J#.  The following code is written by J++ for dll file.  I need to either convert those code into J# or create new J# dll file.  However, I have no clue how to start it.  Could someone help me as soon as you can.  I really appreciate it.  I only have one day to finish this assignment.


import java.io.*;
/**
 * This class is designed to be packaged with a COM DLL output format.
 * The class has no standard entry points, other than the constructor.
 * Public methods will be exposed as methods on the default COM interface.
 * @com.register ( clsid=5BD97072-819B-4FFF-A6BD-6980F93EBA49, typelib=842EE387-31B5-4F8F-AECC-F449F5204038 )
 */
public class AnytoAscii_String
{
 String exename,params;
 public boolean Application(String name)
 {
  exename = name;
  return true;
 }
 public boolean Parameters(String arguments)
 {
  params = arguments;
  return true;
 }

 public String ExecuteDosApp()
 {
  String res = "";
  StringBuffer strBuf = new StringBuffer();
  // program variables
  try
  {
   Runtime rt = Runtime.getRuntime();
   String tmp = exename +" "+params;
   Process ps = rt.exec(tmp );
   BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()));
   String inputLine;
   while ((inputLine = in.readLine()) != null)
   {
    //res = res.concate(inputLine);
    //res = res + "\r\n";
    strBuf = strBuf.append(inputLine);
    strBuf = strBuf.append("\r\n");
    
   }
   res=strBuf.toString();
   in.close();
   ps.destroy();
  }
  
     //  catch(InterruptedException ie){return "Error";}
  catch(IOException io){return "Error";}
  return res ;
 }
}





Answer this question

how to create DLL file in J# or convert J++ dll into J# dll

  • MrFaith

    Hi,

    You just need to open Visual Studio Command prompt. You can open it from Program Files > Microsoft Visual Studio > Visual Studio Tools.

    Thanks.



  • originsnone

    Hi,
    Can you please write here what exactly your assignment is What i get from your last two post is that you have some code written in J++ and you want to port it to .net (using j#) and consume it in other .net/COM applications.

    As i wrote in my last post ...
    1. If you are working on Visual Studio 2003 or 2005 (non express version) then you can just open J++ project in in IDE and upgrade it to J#.
    2. If you are on Express then you can create a new J# class library project and replace the code of Class1.jsl with the code you have pasted above.

    After following either of these two approaches your code has been upgraded to J#. Now you need to compile it. Please follow following steps....

    1. Right click on project node in solution eplorer.
    2. Click properties in context menue.
    3. In Application tab, click on Assembly Information button.
    4. In the dialog box, check the "Make Assembly Com Visible" check box.
    5. Now click on build TAB.
    6. Check "Register For Com Interop" check box.
    7. Build your project (Ctrl + Shift + B).

    Now your project has been built successfully with no errors but you will see following warning...

    warning VJS1553: A COM type library for the class 'AnytoAscii_String' was not found. COM applications that used to access this class using a type library will not work.

    This warning is given by compiler to inform you that type library for your dll was not registered on this machine. So if you want to use this managed assembly in COM world then you need to register it. If you want to register it then...

    8. Open visual studio command prompt (Program files > visual Studio 2005 > Visual Studio Tools > Visual Studio Command Prompt if your are using visual studio 2003 or 2005 (non express) or open normal command prompt and go to D:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin if you are on express).
    9. Issue following command...

          Oleview <full path to your tlb file>

        you can find the tlb file at bin\debug or bin\release folder of your application.


    At this stage you are ready to consume your dll in both .net and com world.

    To consume the dll in .net world, just refer the J# assembly (built in step 7) in your other projects where you want to consume it.
    To consume the dll in com world, just refer the tlb file you registered in step9.

    Hope this serves your purpose.
    If not then please post back.

    Thanks.




  • _cham

    I guess it does not work this way.  is anyone can modify the code above into interface code written in J#

    for example:

    public interface ITest
    {
    public void set_Value();
    public int get_Value();
    }

    public class Class1 implements ITest
    {
    ........................
    }

    I am so depressed right now.  I don't know how to tell my new boss that I could not finish this assignment...Sad


  • Mika Joronen

    Hii Jai,

    Its a good article for VJ++ conversion.

    Actually we have a Java code and want to convert it into J# dll.

    Kindly suggest me how to go about with it.

    Thanks & Regards,

    Tanmoy.

    Pune.


  • frank stone

    Hi,

    Please check my very first post in this thread, posted on 11/30/2005. If it doesn't help then please let me know your exact requirement. I will be more than happy in helping you out.

    Thanks.



  • perepe

    Hi Jai,

    Thanks a lot for the reply. But i think the post (11/30/2005) which you mentioned about is dealing with Microsoft's VJ++ to J# conversion and not that of Sun Java to J#.

    We need to convert Sun Microsystem's Java to Microsoft's J# dll specifically.

    Kindly suggest me how to go about with it.

    Thanks & Regards,

    Tanmoy.

    Pune.


  • bobm

    Hi,

    Good to know that my reply was useful.

    What i mean is, If you are referring the generated assembly in Managed code, e.g. C# or asp .net, then just refer the generated assembly. Visual J# is also a managed language and the compiler generates assemblies which are targeted for .net platform.

    If you are trying to use the assembly in non - manged world, i.e the classes exposed by this assembly are to be consumed by unmanaged code like COM or native C++ or C then you will have to use managed/unmanaged interop technology.

    So from ASP .net you can just instantiate the J# generated assemblies and it will work.

    Thanks.



  • la

    Hi,

    The steps I wrote above are specific to VS 2005. Sorry for not mentioning it. In VS2003 you need to follow these steps... (assuming you have already migrated your app to VS 2003)

    1.  Open assemblyinfo.jsl or if assemblyinfo.jsl is not there, you can open any of your .jsl or .java files.

    2. paste following line of code after import statements...

    /** @assembly System.Runtime.InteropServices.ComVisible(true)*/

    3. Build your project.

    4. Open visual studio command prompt (Program files > visual Studio 2003 > Visual Studio Tools > Visual Studio Command Prompt if your are using visual studio 2003 or 2005 (non express) or open normal command prompt and go to D:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin if you are on express).

    5. In the command prompt go to the output directory of your project (the directory where dll has been generated).

           tlbexp ClassLibrary9.dll /out:ClassLibrary9.tlb

           where ClassLibrary9  must be replaced with your assembly name.


    6. Issue following command...

          Oleview ClassLibrary9.tlb
        you can find the tlb file at bin\debug or bin\release folder of your application.


    At this stage you are ready to consume your dll in both .net and com world.

    To consume the dll in .net world, just refer the J# assembly (built in step 7) in your other projects where you want to consume it.
    To consume the dll in com world, just refer the tlb file you registered in step9.

    Hope this serves your purpose.
    If not then please post back.

    Thanks.



    Jaiprakash (VJ# Team)



  • cosmicstudio

    Hi,

    This is some great information on converting Visual J++ to Visual J#. I'm a newbie too but I can successfully create a new Visual J# dll using this instruction. I have one question though:

    1/ If I'm using the dll from my old Visual J++ project, I can register and call it from my ASP pages using server.createobject command. You said if I use .NET then use the myObject.dll in bin/debug folder. For other COM then use myObject.tlb I'm not sure what you mean here. Could you please show me how to call this object from ASP page


  • Aaron C

    Jaiprakash,

    I'm still unclear about the managed/unmanaged interop technology. Here's an example of my ASP page. (not ASP.NET)

    <html>
    <head>
    <title>Test IPCWebAPI</title>
    </head>
    <body>
    <h1>Test IPC Web COM object.</h1>
    <%
    Dim strRequest, strResult, IPCWebAPI

    Set IPCWebAPI = Server.CreateObject("IPCWebCOM.IPCWebAPI")
    strRequest = "This is my test request"
    Response.Write (strRequest & "<br><hr width='50%'>")

    strResult = IPCWebAPI.sendTransaction("This is my test request",1)
    Response.Write (strResult & "<br>...")

    %>

    </body>
    </html>

    Where IPCWebCOM is my object and IPCWebAPI is my class and sendTransaction is one public function of my class. This method use to be OK with my old DLL generated from J++, but I seem to have problem with the object generated from J#

    The sendTransaction function won't do anything but return the request back and write it out to screen. The error I have is at the Server.CreateObject("IPCWebCOM.IPCWebAPI") and the error message is "Invalid class string".

    It doesn't know what IPCWebCOM.IPCWebAPI is.

    Dylan


  • ScofferX

    Tongue Tied Please help ~ it drives me so crazy
  • Big Ticket

    Hi,
    Migration from VJ++ to J# is supported in Visual Studio 2003 and 2005 as well, but not on J# Express.

    If you are working in Visual Studio 2005 edition (Not J# ecpress) then just open .vjp file in visual studio IDE. Doing so will open up a migration wizard. This wizard is self explainatory and contains enough help pointers to guide you through the migration. For additional help please refer this link.

    If you are working on J# express then you can't migrate the J++ solution directly. What you can do is...

    1. Open J# express.
    2. Create a new class library project.
    3. delete the class1.jsl file from solution explorer (this is not required though)
    3. Add your code file (.java) as an existing item to your project.
        3.1 Right click on project node in solution explorer.
        3.2 Click Add > Existing item.
        3.3 Browse to the code fie.
        3.4 select it and click ok.
    4. Build your solution.

    If you need more help or face any issues in conversion then please let us know.

    Thanks.


  • Timmy Lajaunie

    Hello

    Let me clarify the problem again.

    My original file is written in COM DLL in Microsoft Visual J++ 6.0. After upgrading to J# in Microsoft Visual Studio 2003 system, it could not work well as usual and the warning message comes out every time "A COM type library for the class was not found. COM application that used to access this class using a type library will not work" after building all succeeded.

    In my original code, there is register as

    Public methods will be exposed as methods on the default COM interface.* @com.register ( clsid=27B5BC4F-19CF-4329-9893-C9F127000930, typelib=A386DF36-48D4-4841-AA41-C99240C72DFF )*/

    I know it does not work in Net system but how I can register this class When I try to use "regsvr32" function in command prompt, the error message keeps pop up "the entry point could not be found, the file can not be registered." I believe there is nothing wrong with code because the code should be working well in J# if the code works fine in vj++. I guess there is way I need to do register the class manually but I can not find the pathway to do that.

    Your nine steps could not be used in microsoft visual studio 2003. I don't see the application tab after following your step 2.

    Please keeps working with me to figure out this issue. I belive the solution will help others whoever wants to create com dll files in .net system.

    thanks.


  • volkerm

    The command prompt does not recognize tlbexp and Oleview functions.

    Do you know where I can download those two exe.


  • how to create DLL file in J# or convert J++ dll into J# dll