Re: Invoking dll functions using winsock from java

"Mcnamara, Sean D" <[email protected]> Fri, 6 Jan 2006 08:50:19 -0500
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <57F935D6BB6B2543AF5D835DCE7CAF270F8DFF@MD61EX100.ad.honeywell-tsi.com>
Sachin,

Ok, first, let me make sure I understand what you're doing. You have a third
party DLL (non-Microsoft) that depends on MSWinsockLib.Winsock -- correct?
If this is so, in order to call this function you need two stubs:

1. A stub for the third-party DLL
2. A stub for the MSWinsockLib.Winsock object (and any non-primitive,
non-built-in Object subclasses that the Winsock object has or uses as
members).

To accomplish the second goal, you need to open MSWINSCK.OCX in the Jawin
Type Browser. Then navigate to the MSWinsockLib.Winsock Dispatch and CoClass
to generate a total of two .java files, _Winsock.java and Winsock.java.

Once you have a stub for the DLL and for Winsock, you might have (in the
simple case) just 4 Java files as an interface to these natives:

_MyThirdPartyClass.java
MyThirdPartyClass.java
_Winsock.java
Winsock.java

The ones that begin with an underscore are concrete, instantiable classes
that you need to make an instance of. When you are done using them in the
Java program, call the .close() method on them (unless you have the LATEST
sources to eliminate this that Roger committed to CVS yesterday, hehe.)

In order to *initialize* the COM object, rather than creating an empty
object, you need to invoke the constructor of each concrete class that
accepts a GUID (CLSID) as its parameter. This GUID will be
MyThirdPartyClass.CLSID and Winsock.CLSID, respectively.

For instance, without even looking at the Java code generated, the proper
way to instantiate a _Winsock object given the above files would be:

_Winsock winsock = new _Winsock(Winsock.CLSID);

If you just do _Winsock winsock = new _Winsock(); you are sort of doing the
same thing as, in Java, ArrayList al = null;

Now let me expand on something I said earlier. As I am not familiar with the
Winsock API I don't know whether you will need to be dealing with other
Winsock-specific objects before you pass the Winsock object into the
EstablishConnection(WSock) method. If there are other objects you need to
use IN JAVA, you need to generate stubs for them. If the objects are used
internally but you don't need to operate on them, no stubs are needed.

HTH,
-Sean



-----Original Message-----
From: Discussion of Java/Win32/COM integration with Jawin
[mailto:[email protected]] On Behalf Of sachin ranglani
Sent: Friday, January 06, 2006 6:54 AM
To: [email protected]
Subject: [JAWIN] Invoking dll functions using winsock from java

Hi,

I need to invoke a third party dll from java. I have generated stubs using
jawin but I am not sure how to use them. The dll has the following function
:

*     EstablishConnection(WSock As Object)
        This method established the connection to the Host though the IP
sockets.
        WSock is an instance of MSWinsockLib.Winsock

It uses the MSWINSCK.OCX. Can someone provide a sample code that shows how
to use the stubs once generated using the type browser...I will be attaching
the dll/ocx for your reference in next mail..not sure if an attachment can
be posted on this list.

Thanks,
Sachin


--
_______________________________________________

Search for businesses by name, location, or phone number.  -Lycos Yellow
Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp
?SRC=lycos10

NOTICE: This communication, including any attachment, contains information
that may be confidential or privileged,
and is intended solely for the entity or individual to whom it is addressed.
If you are not the intended recipient, please notify
 the sender at once, and you should delete this message and are hereby
notified that any disclosure, copying, or distribution
of this message is strictly prohibited. Nothing in this email, including any
attachment, is intended to be a legally binding signature.