<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Multunus &#187; Jeevan</title>
	<atom:link href="http://www.multunus.com/author/jeevan/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.multunus.com</link>
	<description>Multunus Blog</description>
	<lastBuildDate>Mon, 30 Jan 2012 12:02:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with DLLs, the Java way</title>
		<link>http://www.multunus.com/2010/01/working-with-dlls-the-java-way/</link>
		<comments>http://www.multunus.com/2010/01/working-with-dlls-the-java-way/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 12:20:51 +0000</pubDate>
		<dc:creator>Jeevan</dc:creator>
				<category><![CDATA[All Posts]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.multunus.com/?p=711</guid>
		<description><![CDATA[We had a very simple requirement, to invoke my DLLs using Java code for couple of reasons:

 We want to reuse application code built for a .NET application
 We want to integrate the DLLs with a Java based sever technology
 Should be simple enough to maintain the code by .NET professionals

There are couple of Java-COM [...]]]></description>
			<content:encoded><![CDATA[<p>We had a very simple requirement, to invoke my DLLs using Java code for couple of reasons:</p>
<ol>
<li> We want to reuse application code built for a .NET application</li>
<li> We want to integrate the DLLs with a Java based sever technology</li>
<li> Should be simple enough to maintain the code by .NET professionals</li>
</ol>
<p>There are couple of Java-COM bridging solutions I came across.</p>
<ul>
<li> <a id="o-ek" title="Java Native Interface (JNI)" href="http://en.wikipedia.org/wiki/Java_Native_Interface">Java Native Interface (JNI)</a></li>
<li> <a id="m-.." title="JACOB" href="http://sourceforge.net/projects/jacob-project/">JACOB</a></li>
<li> <a id="r0rf" title="Scriptom (Groovy - COM Scripting)" href="http://groovy.codehaus.org/COM+Scripting">Scriptom (Groovy &#8211; COM Scripting)</a></li>
<li> <a id="h:uh" title="Java Native Access (JNA)" href="https://jna.dev.java.net/">Java Native Access (JNA)</a></li>
<li> <a id="ck4a" title="JNBridge" href="http://www.jnbridge.com/">JNBridge</a></li>
</ul>
<p>In this post, we&#8217;ll see how Scriptom can be used to access DLLs.</p>
<p>Scriptom is a module in Groovy (A Java VM based scripting language) which wraps the JACOB classes to make it more usable. Scriptom&#8217;s syntax looks like VB.NET code.</p>
<p>Lets jump in to the sample application.</p>
<p>Assume that we have a VB class named TimerState in the TestDLL VB.NET project, exposes the COM, signed and generates the DLLs.</p>
<p>Following is the TimerState VB class. In this class, we have an event <em>UpdateTime</em> which raises an event when to notify updated time.</p>
<pre class="brush: vb;">
 ﻿&lt;Microsoft.VisualBasic.ComClass()&gt; Public Class TimerState

    Public Event UpdateTime(ByVal Jump As Double)

    Public Sub TimerTask(ByVal Duration As Double)
        Dim Start As Double
        Dim Second As Double
        Dim SoFar As Double

        Start = Timer
        SoFar = Start
        Do While Timer &lt; Start + Duration
            If Timer - SoFar &gt;= 0.1 Then
                SoFar = SoFar + 0.1
                RaiseEvent UpdateTime(Timer - Start)
            End If
        Loop
    End Sub
End Class
</pre>
<p>We want to use this logic in the Scriptom code and do something whenever a UpdateTime event is raised. Here are the steps:</p>
<ol>
<li> Register the DLLs (this is required step for the Java Virtual Machine to get meta data about the DLLs)</li>
<li> Download Scriptom</li>
<li> Copy the jacob-*.dll to any system PATH</li>
<li> Have all the JARS from Scriptom jar folder available in the CLASSPATH</li>
</ol>
<p>Following is the sample code for invoking</p>
<pre class="brush: vb;">
import org.codehaus.groovy.scriptom.ActiveXObject // Imports the ActiveX object class which holds the reference to the class in DLL

def timer = new ActiveXObject(&quot;TestDLL.TimerState&quot;) // Looks for the meta data in the registry with &quot;TestDLL.TimerState&quot; name and creates a reference to that class

def time = 1.00

timer.events.UpdateTime = { variants -&gt; // event registration for UpdateTime event in the VB class. Variants holds the data passed from the event. In this case, it is Jump value.
    println &quot;UpdateTime: &quot; + variants[0] // We're just printing the upated time
}

timer.TimerTask(time) // starting the timer task in TimerState class
while(true) { // keeping itself alive to respond when timer events are raised
}
</pre>
<div style="text-align: left;">Please refer <a id="hzki" title="COM Data Types in Scriptom" href="http://groovy.codehaus.org/COM+Data+Types+in+Scriptom">COM Data Types in Scriptom</a> for the .NET data types supported in Scriptom.</div>
<p><strong><span style="font-weight: normal;"><br />
In the next post, we&#8217;ll discuss about JNBridge, a comercial solution.</span></strong></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 694px; width: 1px; height: 1px;">
<p>﻿&lt;Microsoft.VisualBasic.ComClass()&gt; Public Class TimerState</p>
<p>Public Event UpdateTime(ByVal Jump As Double)</p>
<p>Public Sub TimerTask(ByVal Duration As Double)<br />
Dim Start As Double<br />
Dim Second As Double<br />
Dim SoFar As Double</p>
<p>Start = Timer<br />
SoFar = Start<br />
Do While Timer &lt; Start + Duration<br />
If Timer &#8211; SoFar &gt;= 0.1 Then<br />
SoFar = SoFar + 0.1<br />
RaiseEvent UpdateTime(Timer &#8211; Start)<br />
End If<br />
Loop<br />
End Sub<br />
End Class</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.multunus.com/2010/01/working-with-dlls-the-java-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

