merged R-1_9 release tag against the root-B-1_9

This commit is contained in:
clay_shooter
2005-02-26 21:32:27 +00:00
parent ebb1eddb69
commit bcf7bb0f85
132 changed files with 7134 additions and 4068 deletions

View File

@@ -1,88 +1,88 @@
- ADO Wrapper for JACOB - Copyright 1999, Dan Adler
This sample shows how to generate more strongly typed wrapper classes
for the JACOB automation classes. These are pure java classes which
extend com.jacob.com.Dispatch and delegate all the methods to the
unedrlying IDispatch pointer. This methodology is similar to the way
MFC does automation wrappers, rather than using the @com directives
to invisibly delegate the calls, as the Microsoft VM does.
The ADO wrappers in this directory are not a part of the JACOB
distribution, however, they demonstrate the preferred way to create
wrappers around the core functionality. The wrappers included here are
not a complete set, but they could easily be extended to provide all
the functionality of the com.ms.wfc.data classes.
The code in test.java demonstrates two ways to get a Recordset
from SQL Server. In this case, I query for the authors in the 'pubs'
database once by opening a Recordset object directly, and once by
using the Command and Connection objects. The same code, using the WFC
wrappers can be found in ms\testms.java in case you want to compare
the performace. You can run the test.java demo in the MS VM as well.
The constructor of the wrapper is used to create an instance.
For example, the user can write:
Connection c = new Connection();
The code for the Connection constructor is shown here:
public Connection()
{
super("ADODB.Connection");
}
it simply delegates to the com.jacob.com.Dispatch constructor which
takes a ProgID.
Since I don't have a tool like JACTIVEX yet to create the wrappers
automatically from the type library, I created them by hand by using
the JACTIVEX'ed version as a starting point, and replacing the @com
calls with delegated calls to JACOB classes. A simple PERL program
could probably be used to automate this step.
In order to return strongly typed wrappers from method calls, I had to
create a special constructor which constructs the wrapper class instance
and copies over the IDispatch pointer. This is because I can't cast a
java Dispatch object to a super class object.
For example, the Command class has a method like this:
public Connection getActiveConnection();
Ideally, I would like the wrapper code to say:
public Connection getActiveConnection()
{
// this doesn't work
return (Connection)Dispatch.get(this, "ActiveConnection").toDispatch());
}
Thereby wrapping the returned Dispatch pointer in a Connection object.
But, since I can't cast in this way, I use the following construct:
public Connection getActiveConnection()
{
// this works
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
Which uses a special constructor inserted into the Connection class:
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Connection(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
I have to add this constructor to any class whose instances I want
to return from wrapped calls.
- ADO Wrapper for JACOB - Copyright 1999, Dan Adler
This sample shows how to generate more strongly typed wrapper classes
for the JACOB automation classes. These are pure java classes which
extend com.jacob.com.Dispatch and delegate all the methods to the
unedrlying IDispatch pointer. This methodology is similar to the way
MFC does automation wrappers, rather than using the @com directives
to invisibly delegate the calls, as the Microsoft VM does.
The ADO wrappers in this directory are not a part of the JACOB
distribution, however, they demonstrate the preferred way to create
wrappers around the core functionality. The wrappers included here are
not a complete set, but they could easily be extended to provide all
the functionality of the com.ms.wfc.data classes.
The code in test.java demonstrates two ways to get a Recordset
from SQL Server. In this case, I query for the authors in the 'pubs'
database once by opening a Recordset object directly, and once by
using the Command and Connection objects. The same code, using the WFC
wrappers can be found in ms\testms.java in case you want to compare
the performace. You can run the test.java demo in the MS VM as well.
The constructor of the wrapper is used to create an instance.
For example, the user can write:
Connection c = new Connection();
The code for the Connection constructor is shown here:
public Connection()
{
super("ADODB.Connection");
}
it simply delegates to the com.jacob.com.Dispatch constructor which
takes a ProgID.
Since I don't have a tool like JACTIVEX yet to create the wrappers
automatically from the type library, I created them by hand by using
the JACTIVEX'ed version as a starting point, and replacing the @com
calls with delegated calls to JACOB classes. A simple PERL program
could probably be used to automate this step.
In order to return strongly typed wrappers from method calls, I had to
create a special constructor which constructs the wrapper class instance
and copies over the IDispatch pointer. This is because I can't cast a
java Dispatch object to a super class object.
For example, the Command class has a method like this:
public Connection getActiveConnection();
Ideally, I would like the wrapper code to say:
public Connection getActiveConnection()
{
// this doesn't work
return (Connection)Dispatch.get(this, "ActiveConnection").toDispatch());
}
Thereby wrapping the returned Dispatch pointer in a Connection object.
But, since I can't cast in this way, I use the following construct:
public Connection getActiveConnection()
{
// this works
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
Which uses a special constructor inserted into the Connection class:
/**
* This constructor is used instead of a case operation to
* turn a Dispatch object into a wider object - it must exist
* in every wrapper class whose instances may be returned from
* method calls wrapped in VT_DISPATCH Variants.
*/
public Connection(Dispatch d)
{
// take over the IDispatch pointer
m_pDispatch = d.m_pDispatch;
// null out the input's pointer
d.m_pDispatch = 0;
}
I have to add this constructor to any class whose instances I want
to return from wrapped calls.

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
// Enum: CommandTypeEnum

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;
public class Field extends Dispatch

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;
public class Fields extends Dispatch

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;
public class Recordset extends Dispatch

View File

@@ -1,4 +1,4 @@
package samples.ado;
package com.jacob.samples.ado;
import com.jacob.com.*;
public class test

View File

@@ -1,8 +1,8 @@
<title>Applet Test (1.1)</title>
<h1>Applet Test (1.1)</h1>
<hr>
<applet code=AppTest.class width=400 height=400>
</applet>
<hr>
<a href="AppTest.java">The source.</a>
<br>
<title>Applet Test (1.1)</title>
<h1>Applet Test (1.1)</h1>
<hr>
<applet code=AppTest.class width=400 height=400>
</applet>
<hr>
<a href="AppTest.java">The source.</a>
<br>

View File

@@ -1,4 +1,4 @@
package samples.applet;
package com.jacob.samples.applet;
import java.awt.*;
import java.awt.event.*;
@@ -16,7 +16,7 @@ public class AppTest extends Applet implements ActionListener
TextField out;
Button calc;
ActiveXComponent sC = null;
Object sControl = null;
Dispatch sControl = null;
/**
* startup method

View File

@@ -1,4 +1,4 @@
package samples.servlet;
package com.jacob.samples.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -44,7 +44,7 @@ public class JacobScript extends javax.servlet.http.HttpServlet
String expr = (String)req.getParameter("expr");
// make sure we have a session
HttpSession session = req.getSession(true);
Object sControl = null;
Dispatch sControl = null;
if (session.isNew())
{
// initialize the control and store it on the session
@@ -56,7 +56,7 @@ public class JacobScript extends javax.servlet.http.HttpServlet
}
else
{
sControl = session.getValue("control");
sControl = (Dispatch)session.getValue("control");
}
Variant result = Dispatch.call(sControl, "Eval", expr);
// display a form

View File

@@ -1,44 +1,44 @@
This sample runs in Weblogic 5.1 as a servlet.
1. Compile this file (make sure you have jdk1.2 installed or the
javax.servlet.* classes in your classpath).
2. Make sure the weblogic policy file allows native access. The easiest
way is to replace the contents with this:
grant codeBase "file:d:/weblogic/-" {
permission java.security.AllPermission;
};
grant codeBase "file:/c:/classes/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${java.home}/lib/ext/-" {
permission java.security.AllPermission;
};
grant {
permission java.security.AllPermission;
};
3. Add the servlet to the weblogic.properties file:
weblogic.httpd.register.JacobScript=JacobScript
4. Either add your CLASSPATH to weblogic.classpath in startWebLogic.cmd
or copy the com directory into weblogic/myserver/servletclasses
5. Copy the jacob/samples/servlet/* into weblogic/myserver/servletclasses
6. Start weblogic
7. Type the url: http://localhost:7001/JacobScript into the browser
(If you run on port 7001)
8. Enter a VBScript expression like:
1+2
Now
"hello" & " world"
etc.
and watch the MS Script control (which you must have installed)
evaluate and return the result.
This sample runs in Weblogic 5.1 as a servlet.
1. Compile this file (make sure you have jdk1.2 installed or the
javax.servlet.* classes in your classpath).
2. Make sure the weblogic policy file allows native access. The easiest
way is to replace the contents with this:
grant codeBase "file:d:/weblogic/-" {
permission java.security.AllPermission;
};
grant codeBase "file:/c:/classes/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${java.home}/lib/ext/-" {
permission java.security.AllPermission;
};
grant {
permission java.security.AllPermission;
};
3. Add the servlet to the weblogic.properties file:
weblogic.httpd.register.JacobScript=JacobScript
4. Either add your CLASSPATH to weblogic.classpath in startWebLogic.cmd
or copy the com directory into weblogic/myserver/servletclasses
5. Copy the jacob/samples/servlet/* into weblogic/myserver/servletclasses
6. Start weblogic
7. Type the url: http://localhost:7001/JacobScript into the browser
(If you run on port 7001)
8. Enter a VBScript expression like:
1+2
Now
"hello" & " world"
etc.
and watch the MS Script control (which you must have installed)
evaluate and return the result.

View File

@@ -1,4 +1,4 @@
package samples.test;
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;

View File

@@ -1,40 +1,40 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class DispatchTest
{
public static void main(String[] args)
{
ComThread.InitSTA();
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
Object xlo = xl.getObject();
try {
System.out.println("version="+xl.getProperty("Version"));
System.out.println("version="+Dispatch.get(xlo, "Version"));
Dispatch.put(xlo, "Visible", new Variant(true));
Object workbooks = xl.getProperty("Workbooks").toDispatch();
Object workbook = Dispatch.get(workbooks,"Add").toDispatch();
Object sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
Object a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
new Object[] {"A1"},
new int[1]).toDispatch();
Object a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
new Object[] {"A2"},
new int[1]).toDispatch();
Dispatch.put(a1, "Value", "123.456");
Dispatch.put(a2, "Formula", "=A1*2");
System.out.println("a1 from excel:"+Dispatch.get(a1, "Value"));
System.out.println("a2 from excel:"+Dispatch.get(a2, "Value"));
Variant f = new Variant(false);
Dispatch.call(workbook, "Close", f);
} catch (Exception e) {
e.printStackTrace();
} finally {
xl.invoke("Quit", new Variant[] {});
ComThread.Release();
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class DispatchTest
{
public static void main(String[] args)
{
ComThread.InitSTA();
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
Dispatch xlo = xl.getObject();
try {
System.out.println("version="+xl.getProperty("Version"));
System.out.println("version="+Dispatch.get(xlo, "Version"));
Dispatch.put(xlo, "Visible", new Variant(true));
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
Dispatch workbook = Dispatch.get(workbooks,"Add").toDispatch();
Dispatch sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
new Object[] {"A1"},
new int[1]).toDispatch();
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
new Object[] {"A2"},
new int[1]).toDispatch();
Dispatch.put(a1, "Value", "123.456");
Dispatch.put(a2, "Formula", "=A1*2");
System.out.println("a1 from excel:"+Dispatch.get(a1, "Value"));
System.out.println("a2 from excel:"+Dispatch.get(a2, "Value"));
Variant f = new Variant(false);
Dispatch.call(workbook, "Close", f);
} catch (Exception e) {
e.printStackTrace();
} finally {
xl.invoke("Quit", new Variant[] {});
ComThread.Release();
}
}
}

View File

@@ -1,4 +1,4 @@
package samples.test;
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
@@ -14,8 +14,9 @@ class IETest
{
public static void main(String[] args)
{
int delay = 5000; // msec
ActiveXComponent ie = new ActiveXComponent("clsid:0002DF01-0000-0000-C000-000000000046");
Object ieo = ie.getObject();
Dispatch ieo = ie.getObject();
try {
Dispatch.put(ieo, "Visible", new Variant(true));
Dispatch.put(ieo, "AddressBar", new Variant(true));
@@ -28,9 +29,9 @@ class IETest
optional.noParam();
Dispatch.call(ieo, "Navigate", new Variant("http://www.danadler.com/jacob"));
try { Thread.sleep(5000); } catch (Exception e) {}
try { Thread.sleep(delay); } catch (Exception e) {}
Dispatch.call(ieo, "Navigate", new Variant("http://groups.yahoo.com/group/jacob-project"));
try { Thread.sleep(5000); } catch (Exception e) {}
try { Thread.sleep(delay); } catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
} finally {

View File

@@ -1,4 +1,4 @@
package samples.test;
package com.jacob.samples.test;
/**
* JACOB Outlook sample contributed by
@@ -22,14 +22,14 @@ public class Outlook {
}
private static void recurseFolders(int iIndent, Object o) {
private static void recurseFolders(int iIndent, Dispatch o) {
if (o == null) return;
Object oFolders = Dispatch.get(o, "Folders").toDispatch();
Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
// System.out.println("oFolders=" + oFolders);
if (oFolders == null) return;
Object oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
do {
Object oFolderName = Dispatch.get(oFolder, "Name");
if (null == oFolderName) {
@@ -52,10 +52,10 @@ public class Outlook {
try {
System.out.println("version="+axOutlook.getProperty("Version"));
Object oOutlook = axOutlook.getObject();
Dispatch oOutlook = axOutlook.getObject();
System.out.println("version="+Dispatch.get(oOutlook, "Version"));
Object oNameSpace = axOutlook.getProperty("Session").toDispatch();
Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
System.out.println("oNameSpace=" + oNameSpace);
recurseFolders(0, oNameSpace);

View File

@@ -1,57 +1,47 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* In this case the component is created and used in the same thread
* and it's an Apartment Threaded component, so we call InitSTA.
*/
class ScriptTest
{
public static void main(String args[]) throws Exception
{
ComThread.InitSTA(true);
DispatchEvents de = null;
Dispatch sControl = null;
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
errEvents te = new errEvents();
de = new DispatchEvents(sControl, te);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
// call it twice to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
// call it 3 times to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
ComThread.quitMainSTA();
}
}
}
class errEvents {
public void Error(Variant[] args)
{
System.out.println("java callback for error!");
}
public void Timeout(Variant[] args)
{
System.out.println("java callback for error!");
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* In this case the component is created and used in the same thread
* and it's an Apartment Threaded component, so we call InitSTA.
*/
class ScriptTest
{
public static void main(String args[]) throws Exception
{
ComThread.InitSTA(true);
DispatchEvents de = null;
Dispatch sControl = null;
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
// call it twice to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
// call it 3 times to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
ComThread.quitMainSTA();
}
}
}

View File

@@ -1,98 +1,98 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* This example demonstrates how to make calls between
* two different STA's.
* First, to create an STA, you need to extend the STA class
* and override its OnInit() method. This method will be called
* in the STA's thread so you can use it to create your COM
* components that will run in that STA.
* If you then try to call methods on those components from other
* threads (STA or MTA) - this will fail.
* You cannot create a component in an STA and call its methods
* from another thread.
* You can use the DispatchProxy to get a proxy to any Dispatch
* that lives in another STA. This object has to be created in the
* STA that houses the Dispatch (in this case it's created in the
* OnInit method). Then, another thread can call the toDispatch()
* method of DispatchProxy to get a local proxy. At most ONE (!)
* thread can call toDispatch(), and the call can be made only once.
* This is because a IStream object is used to pass the proxy, and
* it is only written once and closed when you read it.
* If you need multiple threads to access a Dispatch pointer, then
* create that many DispatchProxy objects.
*/
class ScriptTest2 extends STA
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static DispatchProxy sCon = null;
public boolean OnInit()
{
try
{
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
// sCon can be called from another thread
sCon = new DispatchProxy(sControl);
Dispatch.put(sControl, "Language", lang);
errEvents te = new errEvents();
de = new DispatchEvents(sControl, te);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public void OnQuit()
{
System.out.println("OnQuit");
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitSTA();
ScriptTest2 script = new ScriptTest2();
Thread.sleep(1000);
// get a thread-local Dispatch from sCon
Dispatch sc = sCon.toDispatch();
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = Dispatch.call(sc, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* This example demonstrates how to make calls between
* two different STA's.
* First, to create an STA, you need to extend the STA class
* and override its OnInit() method. This method will be called
* in the STA's thread so you can use it to create your COM
* components that will run in that STA.
* If you then try to call methods on those components from other
* threads (STA or MTA) - this will fail.
* You cannot create a component in an STA and call its methods
* from another thread.
* You can use the DispatchProxy to get a proxy to any Dispatch
* that lives in another STA. This object has to be created in the
* STA that houses the Dispatch (in this case it's created in the
* OnInit method). Then, another thread can call the toDispatch()
* method of DispatchProxy to get a local proxy. At most ONE (!)
* thread can call toDispatch(), and the call can be made only once.
* This is because a IStream object is used to pass the proxy, and
* it is only written once and closed when you read it.
* If you need multiple threads to access a Dispatch pointer, then
* create that many DispatchProxy objects.
*/
class ScriptTest2 extends STA
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static DispatchProxy sCon = null;
public boolean OnInit()
{
try
{
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
// sCon can be called from another thread
sCon = new DispatchProxy(sControl);
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public void OnQuit()
{
System.out.println("OnQuit");
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitSTA();
ScriptTest2 script = new ScriptTest2();
Thread.sleep(1000);
// get a thread-local Dispatch from sCon
Dispatch sc = sCon.toDispatch();
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = Dispatch.call(sc, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
}

View File

@@ -0,0 +1,96 @@
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* This example demonstrates how to make calls between
* two different STA's.
* First, to create an STA, you need to extend the STA class
* and override its OnInit() method. This method will be called
* in the STA's thread so you can use it to create your COM
* components that will run in that STA.
* If you then try to call methods on those components from other
* threads (STA or MTA) - this will fail.
* You cannot create a component in an STA and call its methods
* from another thread.
* You can use the DispatchProxy to get a proxy to any Dispatch
* that lives in another STA. This object has to be created in the
* STA that houses the Dispatch (in this case it's created in the
* OnInit method). Then, another thread can call the toDispatch()
* method of DispatchProxy to get a local proxy. At most ONE (!)
* thread can call toDispatch(), and the call can be made only once.
* This is because a IStream object is used to pass the proxy, and
* it is only written once and closed when you read it.
* If you need multiple threads to access a Dispatch pointer, then
* create that many DispatchProxy objects.
*/
class ScriptTest2ActiveX extends STA
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static DispatchProxy sCon = null;
public boolean OnInit()
{
try
{
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
// sCon can be called from another thread
sCon = new DispatchProxy(sC);
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public void OnQuit()
{
System.out.println("OnQuit");
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitSTA();
ScriptTest2ActiveX script = new ScriptTest2ActiveX();
Thread.sleep(1000);
// get a thread-local Dispatch from sCon
ActiveXComponent sc = new ActiveXComponent(sCon.toDispatch());
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = sc.invoke("Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
}

View File

@@ -1,68 +1,68 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* Here we create the ScriptControl component in a separate MTA thread
* and then call the Eval method from the main thread. The main thread
* must also be an MTA thread. If you try to create it as an STA
* then you will not be able to make calls into a component running
* in another thread.
*/
class ScriptTest3 extends Thread
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static boolean quit = false;
public void run()
{
try
{
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
errEvents te = new errEvents();
de = new DispatchEvents(sControl, te);
System.out.println("sControl="+sControl);
while (!quit) sleep(100);
ComThread.Release();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("worker thread exits");
}
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitMTA();
ScriptTest3 script = new ScriptTest3();
script.start();
Thread.sleep(1000);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
System.out.println("setting quit");
script.quit = true;
} catch (ComException e) {
e.printStackTrace();
}
finally
{
System.out.println("main done");
ComThread.Release();
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* Here we create the ScriptControl component in a separate MTA thread
* and then call the Eval method from the main thread. The main thread
* must also be an MTA thread. If you try to create it as an STA
* then you will not be able to make calls into a component running
* in another thread.
*/
class ScriptTest3 extends Thread
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static boolean quit = false;
public void run()
{
try
{
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
System.out.println("sControl="+sControl);
while (!quit) sleep(100);
ComThread.Release();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("worker thread exits");
}
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitMTA();
ScriptTest3 script = new ScriptTest3();
script.start();
Thread.sleep(1000);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
System.out.println("setting quit");
ScriptTest3.quit = true;
} catch (ComException e) {
e.printStackTrace();
}
finally
{
System.out.println("main done");
ComThread.Release();
}
}
}

View File

@@ -0,0 +1,66 @@
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* Here we create the ScriptControl component in a separate MTA thread
* and then call the Eval method from the main thread. The main thread
* must also be an MTA thread. If you try to create it as an STA
* then you will not be able to make calls into a component running
* in another thread.
*/
class ScriptTest3ActiveX extends Thread
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static boolean quit = false;
public void run()
{
try
{
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
System.out.println("sControl="+sC);
while (!quit) sleep(100);
ComThread.Release();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("worker thread exits");
}
}
public static void main(String args[]) throws Exception
{
try {
ComThread.InitMTA();
ScriptTest3ActiveX script = new ScriptTest3ActiveX();
script.start();
Thread.sleep(1000);
Variant result = sC.invoke("Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
System.out.println("setting quit");
ScriptTest3ActiveX.quit = true;
} catch (ComException e) {
e.printStackTrace();
}
finally
{
System.out.println("main done");
ComThread.Release();
}
}
}

View File

@@ -0,0 +1,46 @@
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
/**
* In this case the component is created and used in the same thread
* and it's an Apartment Threaded component, so we call InitSTA.
*/
class ScriptTestActiveX
{
public static void main(String args[]) throws Exception
{
ComThread.InitSTA(true);
DispatchEvents de = null;
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sC.setProperty("Language",lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
Variant result;
result = sC.invoke("Eval",args[0]);
// call it twice to see the objects reused
result = sC.invoke("Eval",args[0]);
// call it 3 times to see the objects reused
result = sC.invoke("Eval",args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
ComThread.quitMainSTA();
}
}
}

View File

@@ -0,0 +1,19 @@
package com.jacob.samples.test;
import com.jacob.com.Variant;
/**
* Extracted from ScriptTest so everyone can see this
*/
public class ScriptTestErrEvents {
public void Error(Variant[] args)
{
System.out.println("java callback for error!");
}
public void Timeout(Variant[] args)
{
System.out.println("java callback for error!");
}
}

View File

@@ -1,67 +1,67 @@
// Face.cpp : Implementation of CMultiFaceApp and DLL registration.
#include "stdafx.h"
#include "MultiFace.h"
#include "Face.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP Face::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IFace1,
&IID_IFace2,
&IID_IFace3,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP Face::get_Face1Name(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name1;
return S_OK;
}
STDMETHODIMP Face::put_Face1Name(BSTR newVal)
{
// TODO: Add your implementation code here
name1 = newVal;
return S_OK;
}
STDMETHODIMP Face::get_Face2Nam(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name2;
return S_OK;
}
STDMETHODIMP Face::put_Face2Nam(BSTR newVal)
{
// TODO: Add your implementation code here
name2 = newVal;
return S_OK;
}
STDMETHODIMP Face::get_Face3Name(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name3;
return S_OK;
}
STDMETHODIMP Face::put_Face3Name(BSTR newVal)
{
// TODO: Add your implementation code here
name3 = newVal;
return S_OK;
}
// Face.cpp : Implementation of CMultiFaceApp and DLL registration.
#include "stdafx.h"
#include "MultiFace.h"
#include "Face.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP Face::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IFace1,
&IID_IFace2,
&IID_IFace3,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP Face::get_Face1Name(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name1;
return S_OK;
}
STDMETHODIMP Face::put_Face1Name(BSTR newVal)
{
// TODO: Add your implementation code here
name1 = newVal;
return S_OK;
}
STDMETHODIMP Face::get_Face2Nam(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name2;
return S_OK;
}
STDMETHODIMP Face::put_Face2Nam(BSTR newVal)
{
// TODO: Add your implementation code here
name2 = newVal;
return S_OK;
}
STDMETHODIMP Face::get_Face3Name(BSTR *pVal)
{
// TODO: Add your implementation code here
*pVal = name3;
return S_OK;
}
STDMETHODIMP Face::put_Face3Name(BSTR newVal)
{
// TODO: Add your implementation code here
name3 = newVal;
return S_OK;
}

View File

@@ -1,63 +1,63 @@
// Face.h: Definition of the Face class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
#define AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// Face
class Face :
public IDispatchImpl<IFace1, &IID_IFace1, &LIBID_MULTIFACELib>,
public IDispatchImpl<IFace2, &IID_IFace2, &LIBID_MULTIFACELib>,
public IDispatchImpl<IFace3, &IID_IFace3, &LIBID_MULTIFACELib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<Face,&CLSID_Face>
{
// IFace1
private:
CComBSTR name1;
// IFace2
CComBSTR name2;
// IFace3
CComBSTR name3;
public:
Face() {}
BEGIN_COM_MAP(Face)
COM_INTERFACE_ENTRY2(IDispatch, IFace1)
COM_INTERFACE_ENTRY(IFace1)
COM_INTERFACE_ENTRY(IFace2)
COM_INTERFACE_ENTRY(IFace3)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
//DECLARE_NOT_AGGREGATABLE(Face)
// Remove the comment from the line above if you don't want your object to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_Face)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
public:
STDMETHOD(get_Face3Name)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face3Name)(/*[in]*/ BSTR newVal);
STDMETHOD(get_Face2Nam)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face2Nam)(/*[in]*/ BSTR newVal);
STDMETHOD(get_Face1Name)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face1Name)(/*[in]*/ BSTR newVal);
};
#endif // !defined(AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
// Face.h: Definition of the Face class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
#define AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// Face
class Face :
public IDispatchImpl<IFace1, &IID_IFace1, &LIBID_MULTIFACELib>,
public IDispatchImpl<IFace2, &IID_IFace2, &LIBID_MULTIFACELib>,
public IDispatchImpl<IFace3, &IID_IFace3, &LIBID_MULTIFACELib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<Face,&CLSID_Face>
{
// IFace1
private:
CComBSTR name1;
// IFace2
CComBSTR name2;
// IFace3
CComBSTR name3;
public:
Face() {}
BEGIN_COM_MAP(Face)
COM_INTERFACE_ENTRY2(IDispatch, IFace1)
COM_INTERFACE_ENTRY(IFace1)
COM_INTERFACE_ENTRY(IFace2)
COM_INTERFACE_ENTRY(IFace3)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
//DECLARE_NOT_AGGREGATABLE(Face)
// Remove the comment from the line above if you don't want your object to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_Face)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
public:
STDMETHOD(get_Face3Name)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face3Name)(/*[in]*/ BSTR newVal);
STDMETHOD(get_Face2Nam)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face2Nam)(/*[in]*/ BSTR newVal);
STDMETHOD(get_Face1Name)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Face1Name)(/*[in]*/ BSTR newVal);
};
#endif // !defined(AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_)

View File

@@ -1,72 +1,72 @@
// MultiFace.cpp : Implementation of DLL Exports.
// Note: Proxy/Stub Information
// To build a separate proxy/stub DLL,
// run nmake -f MultiFaceps.mk in the project directory.
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "MultiFace.h"
#include "MultiFace_i.c"
#include "Face.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Face, Face)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_MULTIFACELib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}
// MultiFace.cpp : Implementation of DLL Exports.
// Note: Proxy/Stub Information
// To build a separate proxy/stub DLL,
// run nmake -f MultiFaceps.mk in the project directory.
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "MultiFace.h"
#include "MultiFace_i.c"
#include "Face.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Face, Face)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_MULTIFACELib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}

View File

@@ -1,12 +1,12 @@
// stdafx.cpp : source file that includes just the standard includes
// stdafx.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif
#include <atlimpl.cpp>
// stdafx.cpp : source file that includes just the standard includes
// stdafx.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif
#include <atlimpl.cpp>

View File

@@ -1,27 +1,27 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#if !defined(AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
#define AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED)
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#if !defined(AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
#define AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__9BF24406_B2E0_11D4_A695_00104BFF3241__INCLUDED)

View File

@@ -1,18 +1,18 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by MultiFace.rc
//
#define IDS_PROJNAME 100
#define IDS_FACE_DESC 101
#define IDR_Face 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 103
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by MultiFace.rc
//
#define IDS_PROJNAME 100
#define IDS_FACE_DESC 101
#define IDR_Face 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 103
#endif
#endif

View File

@@ -1,4 +1,4 @@
package samples.test.atl;
package com.jacob.samples.test.atl;
import com.jacob.com.*;
import com.jacob.activeX.*;

View File

@@ -1,14 +1,14 @@
This example demonstrates how to access multiple interfaces.
To run it, chdir to MultiFace\Debug and run:
regsvr32 MultiFace.dll
Then, run (in this dir):
java MultiFace
As you can see from MultiFace\MultiFace.idl - there are 3 interfaces.
By default JACOB attaches to the default interface.
The file MultiFace.java shows how to use the new Dispatch.QueryInterface
to get access to the other interfaces.
This example demonstrates how to access multiple interfaces.
To run it, chdir to MultiFace\Debug and run:
regsvr32 MultiFace.dll
Then, run (in this dir):
java MultiFace
As you can see from MultiFace\MultiFace.idl - there are 3 interfaces.
By default JACOB attaches to the default interface.
The file MultiFace.java shows how to use the new Dispatch.QueryInterface
to get access to the other interfaces.

View File

@@ -1,38 +1,38 @@
package samples.test;
import com.jacob.com.*;
/*
* This example uses the MathTest sample VB COM DLL under
* the MathProj directory
*/
class math
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
Dispatch test = new Dispatch("MathTest.Math");
testEvents te = new testEvents();
DispatchEvents de = new DispatchEvents(test, te);
System.out.println(Dispatch.call(test, "Add", new Variant(1), new Variant(2)));
System.out.println(Dispatch.call(test, "Mult", new Variant(2), new Variant(2)));
Variant v = Dispatch.call(test, "Mult", new Variant(2), new Variant(2));
// this should return false
System.out.println("v.isNull="+v.isNull());
v = Dispatch.call(test, "getNothing");
// these should return nothing
System.out.println("v.isNull="+v.isNull());
System.out.println("v.toDispatch="+v.toDispatch());
}
}
class testEvents {
public void DoneAdd(Variant[] args)
{
System.out.println("DoneAdd called in java");
}
public void DoneMult(Variant[] args)
{
System.out.println("DoneMult called in java");
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
/*
* This example uses the MathTest sample VB COM DLL under
* the MathProj directory
*/
class math
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
Dispatch test = new Dispatch("MathTest.Math");
testEvents te = new testEvents();
DispatchEvents de = new DispatchEvents(test, te);
System.out.println(Dispatch.call(test, "Add", new Variant(1), new Variant(2)));
System.out.println(Dispatch.call(test, "Mult", new Variant(2), new Variant(2)));
Variant v = Dispatch.call(test, "Mult", new Variant(2), new Variant(2));
// this should return false
System.out.println("v.isNull="+v.isNull());
v = Dispatch.call(test, "getNothing");
// these should return nothing
System.out.println("v.isNull="+v.isNull());
System.out.println("v.toDispatch="+v.toDispatch());
}
}
class testEvents {
public void DoneAdd(Variant[] args)
{
System.out.println("DoneAdd called in java");
}
public void DoneMult(Variant[] args)
{
System.out.println("DoneMult called in java");
}
}

View File

@@ -1,41 +1,41 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class sa_dispatch
{
public static void main(String args[])
{
System.runFinalizersOnExit(true);
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
// wrap the script control in a variant
Variant v = new Variant(sControl);
// create a safe array of type dispatch
SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);
// put the variant in the array
sa.setVariant(0, v);
// take it back out
Variant v2 = sa.getVariant(0);
Dispatch d = v2.toDispatch();
// make sure you can call eval on it
result = Dispatch.call(d, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class sa_dispatch
{
public static void main(String args[])
{
System.runFinalizersOnExit(true);
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
Variant result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
// wrap the script control in a variant
Variant v = new Variant(sControl);
// create a safe array of type dispatch
SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);
// put the variant in the array
sa.setVariant(0, v);
// take it back out
Variant v2 = sa.getVariant(0);
Dispatch d = v2.toDispatch();
// make sure you can call eval on it
result = Dispatch.call(d, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,58 +1,58 @@
package samples.test;
import com.jacob.com.*;
class sa_test
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
SafeArray sa = new SafeArray(Variant.VariantVariant, 3);
sa.fromShortArray(new short[] {1,2,3});
System.out.println("sa short="+sa);
int[] ai = sa.toIntArray();
for(int i=0;i<ai.length;i++) {
System.out.println("toInt="+ai[i]);
}
double[] ad = sa.toDoubleArray();
for(int i=0;i<ad.length;i++) {
System.out.println("toDouble="+ad[i]);
}
sa.fromIntArray(new int[] {100000,200000,300000});
System.out.println("sa int="+sa);
ai = sa.toIntArray();
for(int i=0;i<ai.length;i++) {
System.out.println("toInt="+ai[i]);
}
ad = sa.toDoubleArray();
for(int i=0;i<ad.length;i++) {
System.out.println("toDouble="+ad[i]);
}
Variant av[] = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromDoubleArray(new double[] {1.5,2.5,3.5});
System.out.println("sa double="+sa);
sa.fromFloatArray(new float[] {1.5F,2.5F,3.5F});
System.out.println("sa float="+sa);
sa.fromBooleanArray(new boolean[] {true, false, true, false});
System.out.println("sa bool="+sa);
av = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromCharArray(new char[] {'a','b','c','d'});
System.out.println("sa char="+sa);
sa.fromStringArray(new String[] {"hello", "from", "java", "com"});
System.out.println("sa string="+sa);
av = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromVariantArray(new Variant[] {
new Variant(1), new Variant(2.3), new Variant("hi")});
System.out.println("sa variant="+sa);
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
class sa_test
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
SafeArray sa = new SafeArray(Variant.VariantVariant, 3);
sa.fromShortArray(new short[] {1,2,3});
System.out.println("sa short="+sa);
int[] ai = sa.toIntArray();
for(int i=0;i<ai.length;i++) {
System.out.println("toInt="+ai[i]);
}
double[] ad = sa.toDoubleArray();
for(int i=0;i<ad.length;i++) {
System.out.println("toDouble="+ad[i]);
}
sa.fromIntArray(new int[] {100000,200000,300000});
System.out.println("sa int="+sa);
ai = sa.toIntArray();
for(int i=0;i<ai.length;i++) {
System.out.println("toInt="+ai[i]);
}
ad = sa.toDoubleArray();
for(int i=0;i<ad.length;i++) {
System.out.println("toDouble="+ad[i]);
}
Variant av[] = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromDoubleArray(new double[] {1.5,2.5,3.5});
System.out.println("sa double="+sa);
sa.fromFloatArray(new float[] {1.5F,2.5F,3.5F});
System.out.println("sa float="+sa);
sa.fromBooleanArray(new boolean[] {true, false, true, false});
System.out.println("sa bool="+sa);
av = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromCharArray(new char[] {'a','b','c','d'});
System.out.println("sa char="+sa);
sa.fromStringArray(new String[] {"hello", "from", "java", "com"});
System.out.println("sa string="+sa);
av = sa.toVariantArray();
for(int i=0;i<av.length;i++) {
System.out.println("toVariant="+av[i]);
}
sa.fromVariantArray(new Variant[] {
new Variant(1), new Variant(2.3), new Variant("hi")});
System.out.println("sa variant="+sa);
}
}

View File

@@ -1,61 +1,61 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
public class safearray
{
public static void main(java.lang.String[] args)
{
System.runFinalizersOnExit(true);
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
try {
Object cell;
Object cellstart;
Object cellstop;
SafeArray sAProdText;
Object workbooks = xl.getProperty("Workbooks").toDispatch();
System.out.println("have workbooks");
Object workbook = Dispatch.call(workbooks, "Open", "d:\\jacob_15\\samples\\test\\jacobtest.xls").toDispatch();
System.out.println("Opened File - jacobtest.xls\n");
Object sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
cell = Dispatch.invoke(sheet,"Range",Dispatch.Get,new Object[] {"A1:D1000"},new int[1]).toDispatch();
System.out.println("have cell:"+cell);
sAProdText = Dispatch.get(cell,"Value").toSafeArray();
System.out.println("sa: dim="+sAProdText.getNumDim());
System.out.println("sa: start row="+sAProdText.getLBound(1));
System.out.println("sa: start col="+sAProdText.getLBound(2));
System.out.println("sa: end row="+sAProdText.getUBound(1));
System.out.println("sa: end col="+sAProdText.getUBound(2));
int i;
int lineNumber=1;
boolean stringFound = true;
int n = 0;
for(lineNumber=1; lineNumber < 1000; lineNumber++)
{
for (i = 1 ; i < 4 ; i++ ) {
System.out.println((n++) + " " + lineNumber+" "+i+" " +sAProdText.getString(lineNumber,i));
/*
if (sAProdText.getString(lineNumber,i).compareTo("aaaa") != 0 ) {
System.out.println("Invalid String in line " + lineNumber + " Cell " + i + " Value = " + sAProdText.getString(lineNumber,i));
stringFound = false;
}
}
if (stringFound) {
System.out.println("Valid Strings in line " + lineNumber);
lineNumber++;
}
*/
}
}
Dispatch.call(workbook, "Close");
System.out.println("Closed File\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
xl.invoke("Quit", new Variant[] {});
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
public class safearray
{
public static void main(java.lang.String[] args)
{
System.runFinalizersOnExit(true);
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
try {
Dispatch cell;
Dispatch cellstart;
Dispatch cellstop;
SafeArray sAProdText;
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
System.out.println("have workbooks");
Dispatch workbook = Dispatch.call(workbooks, "Open", "d:\\jacob_15\\samples\\test\\jacobtest.xls").toDispatch();
System.out.println("Opened File - jacobtest.xls\n");
Dispatch sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
cell = Dispatch.invoke(sheet,"Range",Dispatch.Get,new Object[] {"A1:D1000"},new int[1]).toDispatch();
System.out.println("have cell:"+cell);
sAProdText = Dispatch.get(cell,"Value").toSafeArray();
System.out.println("sa: dim="+sAProdText.getNumDim());
System.out.println("sa: start row="+sAProdText.getLBound(1));
System.out.println("sa: start col="+sAProdText.getLBound(2));
System.out.println("sa: end row="+sAProdText.getUBound(1));
System.out.println("sa: end col="+sAProdText.getUBound(2));
int i;
int lineNumber=1;
boolean stringFound = true;
int n = 0;
for(lineNumber=1; lineNumber < 1000; lineNumber++)
{
for (i = 1 ; i < 4 ; i++ ) {
System.out.println((n++) + " " + lineNumber+" "+i+" " +sAProdText.getString(lineNumber,i));
/*
if (sAProdText.getString(lineNumber,i).compareTo("aaaa") != 0 ) {
System.out.println("Invalid String in line " + lineNumber + " Cell " + i + " Value = " + sAProdText.getString(lineNumber,i));
stringFound = false;
}
}
if (stringFound) {
System.out.println("Valid Strings in line " + lineNumber);
lineNumber++;
}
*/
}
}
Dispatch.call(workbook, "Close");
System.out.println("Closed File\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
xl.invoke("Quit", new Variant[] {});
}
}
}

View File

@@ -1,18 +1,18 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class speed
{
public static void main(String args[])
{
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Object sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang);
for(int i=0;i<10000;i++) {
Dispatch.call(sControl, "Eval", "1+1");
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class speed
{
public static void main(String args[])
{
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang);
for(int i=0;i<10000;i++) {
Dispatch.call(sControl, "Eval", "1+1");
}
}
}

View File

@@ -1,276 +1,275 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
class test
{
public static void printArray(boolean a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(int a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(short a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(byte a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(double a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(float a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(String a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(Variant a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(char a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void main(String[] args)
{
// int
System.out.println("Int");
SafeArray ia = new SafeArray(Variant.VariantInt,4);
System.out.println("elem size:"+ia.getElemSize());
int iack[] = new int[] {100000,200000,300000,400000};
printArray(iack);
ia.fromIntArray(iack);
iack = ia.toIntArray();
printArray(iack);
int i4[] = new int[4];
ia.getInts(0, 4, i4, 0);
printArray(i4);
SafeArray ia2 = new SafeArray(Variant.VariantInt,4);
ia2.setInts(0, 4, i4, 0);
iack = ia2.toIntArray();
printArray(iack);
// double
System.out.println("Double");
SafeArray da = new SafeArray(Variant.VariantDouble,4);
System.out.println("elem size:"+da.getElemSize());
double dack[] = new double[] {123.456,456.123,1234567.89,12.3456789};
printArray(dack);
da.fromDoubleArray(dack);
dack = da.toDoubleArray();
printArray(dack);
double d4[] = new double[4];
da.getDoubles(0, 4, d4, 0);
printArray(d4);
SafeArray da2 = new SafeArray(Variant.VariantDouble,4);
da2.setDoubles(0, 4, d4, 0);
dack = da2.toDoubleArray();
printArray(dack);
// float
System.out.println("Float");
SafeArray fa = new SafeArray(Variant.VariantFloat,4);
System.out.println("elem size:"+fa.getElemSize());
float fack[] = new float[] {123.456F,456.123F,1234567.89F,12.3456789F};
printArray(fack);
fa.fromFloatArray(fack);
fack = fa.toFloatArray();
printArray(fack);
float f4[] = new float[4];
fa.getFloats(0, 4, f4, 0);
printArray(f4);
SafeArray fa2 = new SafeArray(Variant.VariantFloat,4);
fa2.setFloats(0, 4, f4, 0);
fack = fa2.toFloatArray();
printArray(fack);
// boolean
System.out.println("Boolean");
SafeArray ba = new SafeArray(Variant.VariantBoolean,4);
System.out.println("elem size:"+ba.getElemSize());
boolean back[] = new boolean[] {true, false, true, false};
printArray(back);
ba.fromBooleanArray(back);
back = ba.toBooleanArray();
printArray(back);
boolean b4[] = new boolean[4];
ba.getBooleans(0, 4, b4, 0);
printArray(b4);
SafeArray ba2 = new SafeArray(Variant.VariantBoolean,4);
ba2.setBooleans(0, 4, b4, 0);
back = ba2.toBooleanArray();
printArray(back);
// char
System.out.println("Char");
SafeArray ca = new SafeArray(Variant.VariantShort,4);
System.out.println("elem size:"+ca.getElemSize());
char cack[] = new char[] {'a','b','c','d'};
printArray(cack);
ca.fromCharArray(cack);
cack = ca.toCharArray();
printArray(cack);
char c4[] = new char[4];
ca.getChars(0, 4, c4, 0);
printArray(c4);
SafeArray ca2 = new SafeArray(Variant.VariantShort,4);
ca2.setChars(0, 4, c4, 0);
cack = ca2.toCharArray();
printArray(cack);
// short
System.out.println("Short");
SafeArray sha = new SafeArray(Variant.VariantShort,4);
System.out.println("elem size:"+sha.getElemSize());
short shack[] = new short[] {1000,2000,3000,4000};
printArray(shack);
sha.fromShortArray(shack);
shack = sha.toShortArray();
printArray(shack);
short sh4[] = new short[4];
sha.getShorts(0, 4, sh4, 0);
printArray(sh4);
SafeArray sha2 = new SafeArray(Variant.VariantShort,4);
sha2.setShorts(0, 4, sh4, 0);
shack = sha2.toShortArray();
printArray(shack);
// string
System.out.println("String");
SafeArray sa = new SafeArray(Variant.VariantString,4);
System.out.println("elem size:"+sa.getElemSize());
String sack[] = new String[] {"aa","bb","cc","dd"};
printArray(sack);
sa.fromStringArray(sack);
sack = sa.toStringArray();
printArray(sack);
String s4[] = new String[4];
sa.getStrings(0, 4, s4, 0);
printArray(s4);
SafeArray sa2 = new SafeArray(Variant.VariantString,4);
sa2.setStrings(0, 4, s4, 0);
sack = sa2.toStringArray();
printArray(sack);
// variant
System.out.println("Variant");
SafeArray va = new SafeArray(Variant.VariantVariant,4);
System.out.println("elem size:"+va.getElemSize());
Variant vack[] = new Variant[]
{
new Variant(1),
new Variant(2.3),
new Variant(true),
new Variant("four"),
};
printArray(vack);
va.fromVariantArray(vack);
vack = va.toVariantArray();
printArray(vack);
Variant v4[] = new Variant[4];
va.getVariants(0, 4, v4, 0);
printArray(v4);
SafeArray va2 = new SafeArray(Variant.VariantVariant,4);
va2.setVariants(0, 4, v4, 0);
vack = va2.toVariantArray();
printArray(vack);
// byte
System.out.println("Byte");
SafeArray bba = new SafeArray(Variant.VariantByte,4);
System.out.println("elem size:"+bba.getElemSize());
byte bback[] = new byte[] {0x1,0x2,0x3,0x4};
printArray(bback);
bba.fromByteArray(bback);
bback = bba.toByteArray();
printArray(bback);
byte bb4[] = new byte[4];
bba.getBytes(0, 4, bb4, 0);
printArray(bb4);
SafeArray bba2 = new SafeArray(Variant.VariantByte,4);
bba2.setBytes(0, 4, bb4, 0);
bback = bba2.toByteArray();
printArray(bback);
try {
// this should throw ComFailException
bba2.fromCharArray(new char[] {'a'});
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
class test
{
public static void printArray(boolean a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(int a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(short a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(byte a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(double a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(float a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(String a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(Variant a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void printArray(char a[])
{
System.out.print("[");
for(int i=0;i<a.length;i++) {
System.out.print(" " + a[i] + " ");
}
System.out.println("]");
}
public static void main(String[] args)
{
// int
System.out.println("Int");
SafeArray ia = new SafeArray(Variant.VariantInt,4);
System.out.println("elem size:"+ia.getElemSize());
int iack[] = new int[] {100000,200000,300000,400000};
printArray(iack);
ia.fromIntArray(iack);
iack = ia.toIntArray();
printArray(iack);
int i4[] = new int[4];
ia.getInts(0, 4, i4, 0);
printArray(i4);
SafeArray ia2 = new SafeArray(Variant.VariantInt,4);
ia2.setInts(0, 4, i4, 0);
iack = ia2.toIntArray();
printArray(iack);
// double
System.out.println("Double");
SafeArray da = new SafeArray(Variant.VariantDouble,4);
System.out.println("elem size:"+da.getElemSize());
double dack[] = new double[] {123.456,456.123,1234567.89,12.3456789};
printArray(dack);
da.fromDoubleArray(dack);
dack = da.toDoubleArray();
printArray(dack);
double d4[] = new double[4];
da.getDoubles(0, 4, d4, 0);
printArray(d4);
SafeArray da2 = new SafeArray(Variant.VariantDouble,4);
da2.setDoubles(0, 4, d4, 0);
dack = da2.toDoubleArray();
printArray(dack);
// float
System.out.println("Float");
SafeArray fa = new SafeArray(Variant.VariantFloat,4);
System.out.println("elem size:"+fa.getElemSize());
float fack[] = new float[] {123.456F,456.123F,1234567.89F,12.3456789F};
printArray(fack);
fa.fromFloatArray(fack);
fack = fa.toFloatArray();
printArray(fack);
float f4[] = new float[4];
fa.getFloats(0, 4, f4, 0);
printArray(f4);
SafeArray fa2 = new SafeArray(Variant.VariantFloat,4);
fa2.setFloats(0, 4, f4, 0);
fack = fa2.toFloatArray();
printArray(fack);
// boolean
System.out.println("Boolean");
SafeArray ba = new SafeArray(Variant.VariantBoolean,4);
System.out.println("elem size:"+ba.getElemSize());
boolean back[] = new boolean[] {true, false, true, false};
printArray(back);
ba.fromBooleanArray(back);
back = ba.toBooleanArray();
printArray(back);
boolean b4[] = new boolean[4];
ba.getBooleans(0, 4, b4, 0);
printArray(b4);
SafeArray ba2 = new SafeArray(Variant.VariantBoolean,4);
ba2.setBooleans(0, 4, b4, 0);
back = ba2.toBooleanArray();
printArray(back);
// char
System.out.println("Char");
SafeArray ca = new SafeArray(Variant.VariantShort,4);
System.out.println("elem size:"+ca.getElemSize());
char cack[] = new char[] {'a','b','c','d'};
printArray(cack);
ca.fromCharArray(cack);
cack = ca.toCharArray();
printArray(cack);
char c4[] = new char[4];
ca.getChars(0, 4, c4, 0);
printArray(c4);
SafeArray ca2 = new SafeArray(Variant.VariantShort,4);
ca2.setChars(0, 4, c4, 0);
cack = ca2.toCharArray();
printArray(cack);
// short
System.out.println("Short");
SafeArray sha = new SafeArray(Variant.VariantShort,4);
System.out.println("elem size:"+sha.getElemSize());
short shack[] = new short[] {1000,2000,3000,4000};
printArray(shack);
sha.fromShortArray(shack);
shack = sha.toShortArray();
printArray(shack);
short sh4[] = new short[4];
sha.getShorts(0, 4, sh4, 0);
printArray(sh4);
SafeArray sha2 = new SafeArray(Variant.VariantShort,4);
sha2.setShorts(0, 4, sh4, 0);
shack = sha2.toShortArray();
printArray(shack);
// string
System.out.println("String");
SafeArray sa = new SafeArray(Variant.VariantString,4);
System.out.println("elem size:"+sa.getElemSize());
String sack[] = new String[] {"aa","bb","cc","dd"};
printArray(sack);
sa.fromStringArray(sack);
sack = sa.toStringArray();
printArray(sack);
String s4[] = new String[4];
sa.getStrings(0, 4, s4, 0);
printArray(s4);
SafeArray sa2 = new SafeArray(Variant.VariantString,4);
sa2.setStrings(0, 4, s4, 0);
sack = sa2.toStringArray();
printArray(sack);
// variant
System.out.println("Variant");
SafeArray va = new SafeArray(Variant.VariantVariant,4);
System.out.println("elem size:"+va.getElemSize());
Variant vack[] = new Variant[]
{
new Variant(1),
new Variant(2.3),
new Variant(true),
new Variant("four"),
};
printArray(vack);
va.fromVariantArray(vack);
vack = va.toVariantArray();
printArray(vack);
Variant v4[] = new Variant[4];
va.getVariants(0, 4, v4, 0);
printArray(v4);
SafeArray va2 = new SafeArray(Variant.VariantVariant,4);
va2.setVariants(0, 4, v4, 0);
vack = va2.toVariantArray();
printArray(vack);
// byte
System.out.println("Byte");
SafeArray bba = new SafeArray(Variant.VariantByte,4);
System.out.println("elem size:"+bba.getElemSize());
byte bback[] = new byte[] {0x1,0x2,0x3,0x4};
printArray(bback);
bba.fromByteArray(bback);
bback = bba.toByteArray();
printArray(bback);
byte bb4[] = new byte[4];
bba.getBytes(0, 4, bb4, 0);
printArray(bb4);
SafeArray bba2 = new SafeArray(Variant.VariantByte,4);
bba2.setBytes(0, 4, bb4, 0);
bback = bba2.toByteArray();
printArray(bback);
try {
// this should throw ComFailException
bba2.fromCharArray(new char[] {'a'});
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,50 +1,49 @@
package samples.test;
import com.jacob.com.*;
import com.jacob.activeX.*;
import java.io.*;
class varSerTest
{
public static void main(String[] args) throws Exception
{
Variant vs1 = new Variant("hi");
Variant vs2 = new Variant(123.456);
FileOutputStream fos = new FileOutputStream("foo.foo");
vs1.Save(fos);
vs2.Save(fos);
fos.close();
Variant vl1 = new Variant();
Variant vl2 = new Variant();
FileInputStream fis = new FileInputStream("foo.foo");
vl1.Load(fis);
vl2.Load(fis);
System.out.println(vl1);
System.out.println(vl2);
// same thing with serialization
fos = new FileOutputStream("foo.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(vs1);
oos.writeObject(vs2);
oos.close();
fos.close();
fis = new FileInputStream("foo.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
Variant vss1, vss2;
vss1 = (Variant)ois.readObject();
vss2 = (Variant)ois.readObject();
ois.close();
fis.close();
System.out.println(vss1);
System.out.println(vss2);
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
import java.io.*;
class varSerTest
{
public static void main(String[] args) throws Exception
{
Variant vs1 = new Variant("hi");
Variant vs2 = new Variant(123.456);
FileOutputStream fos = new FileOutputStream("foo.foo");
vs1.Save(fos);
vs2.Save(fos);
fos.close();
Variant vl1 = new Variant();
Variant vl2 = new Variant();
FileInputStream fis = new FileInputStream("foo.foo");
vl1.Load(fis);
vl2.Load(fis);
System.out.println(vl1);
System.out.println(vl2);
// same thing with serialization
fos = new FileOutputStream("foo.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(vs1);
oos.writeObject(vs2);
oos.close();
fos.close();
fis = new FileInputStream("foo.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
Variant vss1, vss2;
vss1 = (Variant)ois.readObject();
vss2 = (Variant)ois.readObject();
ois.close();
fis.close();
System.out.println(vss1);
System.out.println(vss2);
}
}

View File

@@ -1,23 +1,23 @@
package samples.test;
import com.jacob.com.*;
class variant_test
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
Variant v = new Variant();
v.putInt(10);
System.out.println("got="+v.toInt());
v.putInt(10);
System.out.println("got="+v.toDouble());
v.putString("1234.567");
System.out.println("got="+v.toString());
v.putBoolean(true);
System.out.println("got="+v.toBoolean());
v.putBoolean(false);
System.out.println("got="+v.toBoolean());
v.putCurrency(123456789123456789L);
System.out.println("got="+v.toCurrency());
}
}
package com.jacob.samples.test;
import com.jacob.com.*;
class variant_test
{
public static void main(String[] args)
{
System.runFinalizersOnExit(true);
Variant v = new Variant();
v.putInt(10);
System.out.println("got="+v.toInt());
v.putInt(10);
System.out.println("got="+v.toDouble());
v.putString("1234.567");
System.out.println("got="+v.toString());
v.putBoolean(true);
System.out.println("got="+v.toBoolean());
v.putBoolean(false);
System.out.println("got="+v.toBoolean());
v.putCurrency(123456789123456789L);
System.out.println("got="+v.toCurrency());
}
}