Merging B-1_9_1 back to head
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package com.jacob.samples.test;
|
||||
package com.jacob.samples.access;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
|
||||
/**
|
||||
* this
|
||||
* @author joe
|
||||
*
|
||||
*/
|
||||
class Access
|
||||
{
|
||||
/**
|
||||
@@ -13,9 +18,15 @@ class Access
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
ComThread.InitSTA();
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// this only works for access files pre-access-2000
|
||||
Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// original test used this
|
||||
// ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// my xp box with a later release of access needed this
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
|
||||
// this only works for access files pre-access-2000
|
||||
// this line doesn't work on my xp box in Eclipse
|
||||
//Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// this works when running in eclipse because the test cases run pwd project root
|
||||
Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
|
||||
String sql = "select * from MainTable";
|
||||
// make a temporary querydef
|
||||
Dispatch qd = Dispatch.call(db, "CreateQueryDef","").toDispatch();
|
||||
@@ -23,9 +34,10 @@ class Access
|
||||
Dispatch.put(qd, "SQL", sql);
|
||||
Variant result = getByQueryDef(qd);
|
||||
// the 2-d safearray is transposed from what you might expect
|
||||
System.out.println(result.toSafeArray());
|
||||
System.out.println("resulting array is "+result.toSafeArray());
|
||||
close(db);
|
||||
ComThread.Release();
|
||||
System.out.println("about to call ComThread.Release()");
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,10 +18,7 @@ public class Command extends Dispatch
|
||||
*/
|
||||
public Command(Dispatch dispatchTarget)
|
||||
{
|
||||
// take over the IDispatch pointer
|
||||
m_pDispatch = dispatchTarget.m_pDispatch;
|
||||
// null out the input's pointer
|
||||
dispatchTarget.m_pDispatch = 0;
|
||||
super(dispatchTarget);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
|
||||
@@ -17,10 +17,7 @@ public class Connection extends Dispatch
|
||||
*/
|
||||
public Connection(Dispatch d)
|
||||
{
|
||||
// take over the IDispatch pointer
|
||||
m_pDispatch = d.m_pDispatch;
|
||||
// null out the input's pointer
|
||||
d.m_pDispatch = 0;
|
||||
super(d);
|
||||
}
|
||||
|
||||
// need to wrap Properties
|
||||
|
||||
@@ -11,10 +11,7 @@ public class Field extends Dispatch
|
||||
*/
|
||||
public Field(Dispatch d)
|
||||
{
|
||||
// take over the IDispatch pointer
|
||||
m_pDispatch = d.m_pDispatch;
|
||||
// null out the input's pointer
|
||||
d.m_pDispatch = 0;
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
|
||||
@@ -11,10 +11,7 @@ public class Fields extends Dispatch
|
||||
*/
|
||||
public Fields(Dispatch d)
|
||||
{
|
||||
// take over the IDispatch pointer
|
||||
m_pDispatch = d.m_pDispatch;
|
||||
// null out the input's pointer
|
||||
d.m_pDispatch = 0;
|
||||
super(d);
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
|
||||
@@ -16,10 +16,7 @@ public class Recordset extends Dispatch
|
||||
*/
|
||||
public Recordset(Dispatch d)
|
||||
{
|
||||
// take over the IDispatch pointer
|
||||
m_pDispatch = d.m_pDispatch;
|
||||
// null out the input's pointer
|
||||
d.m_pDispatch = 0;
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
|
||||
@@ -10,40 +10,46 @@ import com.jacob.activeX.*;
|
||||
/**
|
||||
* Applet test case
|
||||
*/
|
||||
public class AppTest extends Applet implements ActionListener
|
||||
{
|
||||
TextField in;
|
||||
TextField out;
|
||||
Button calc;
|
||||
ActiveXComponent sC = null;
|
||||
Dispatch sControl = null;
|
||||
public class AppTest extends Applet implements ActionListener {
|
||||
/**
|
||||
* unique identifier added by Eclipse because this class is serializable
|
||||
*/
|
||||
private static final long serialVersionUID = -6676420357823607065L;
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
setLayout(new FlowLayout());
|
||||
add(in = new TextField("1+1", 16));
|
||||
add(out = new TextField("?", 16));
|
||||
add(calc = new Button("Calculate"));
|
||||
calc.addActionListener(this);
|
||||
TextField in;
|
||||
|
||||
}
|
||||
TextField out;
|
||||
|
||||
/**
|
||||
* action method that receives button actions
|
||||
* @param ev the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ev)
|
||||
{
|
||||
if (sC == null) {
|
||||
String lang = "VBScript";
|
||||
sC = new ActiveXComponent("ScriptControl");
|
||||
sControl = sC.getObject();
|
||||
Dispatch.put(sControl, "Language", lang);
|
||||
Button calc;
|
||||
|
||||
ActiveXComponent sC = null;
|
||||
|
||||
Dispatch sControl = null;
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*/
|
||||
public void init() {
|
||||
setLayout(new FlowLayout());
|
||||
add(in = new TextField("1+1", 16));
|
||||
add(out = new TextField("?", 16));
|
||||
add(calc = new Button("Calculate"));
|
||||
calc.addActionListener(this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* action method that receives button actions
|
||||
* @param ev the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
if (sC == null) {
|
||||
String lang = "VBScript";
|
||||
sC = new ActiveXComponent("ScriptControl");
|
||||
sControl = sC.getObject();
|
||||
Dispatch.put(sControl, "Language", lang);
|
||||
}
|
||||
Variant v = Dispatch.call(sControl, "Eval", in.getText());
|
||||
out.setText(v.toString());
|
||||
}
|
||||
Variant v = Dispatch.call(sControl, "Eval", in.getText());
|
||||
out.setText(v.toString());
|
||||
}
|
||||
}
|
||||
|
||||
47
samples/com/jacob/samples/office/ExcelDispatchTest.java
Normal file
47
samples/com/jacob/samples/office/ExcelDispatchTest.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.jacob.samples.office;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
|
||||
/**
|
||||
* Sample test program snagged out of a question on the sun discussion area.
|
||||
* Run options...
|
||||
* -Djava.library.path=d:/jacob/release -Dcom.jacob.autogc=false -Dcom.jacob.debug=true
|
||||
* @author joe
|
||||
*
|
||||
*/
|
||||
public class ExcelDispatchTest {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ComThread.InitSTA();
|
||||
|
||||
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
|
||||
try {
|
||||
System.out.println("version="+xl.getProperty("Version"));
|
||||
System.out.println("version="+Dispatch.get(xl, "Version"));
|
||||
Dispatch.put(xl, "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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
163
samples/com/jacob/samples/office/WordDocumentProperties.java
Normal file
163
samples/com/jacob/samples/office/WordDocumentProperties.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package com.jacob.samples.office;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComFailException;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Submitted to the Jacob SourceForge web site as a sample 3/2005
|
||||
*
|
||||
* @author Date Created Description Jason Twist 04 Mar 2005 Code opens a locally
|
||||
* stored Word document and extracts the Built In properties and Custom
|
||||
* properties from it. This code just gives an intro to JACOB and there
|
||||
* are sections that could be enhanced
|
||||
*/
|
||||
public class WordDocumentProperties {
|
||||
//Declare word object
|
||||
private ActiveXComponent objWord;
|
||||
|
||||
//Declare Word Properties
|
||||
private Dispatch custDocprops;
|
||||
|
||||
private Dispatch builtInDocProps;
|
||||
|
||||
//the doucments object is important in any real app but this demo doesn't use it
|
||||
//private Dispatch documents;
|
||||
|
||||
private Dispatch document;
|
||||
|
||||
private Dispatch wordObject;
|
||||
|
||||
/**
|
||||
* Empty Constructor
|
||||
*
|
||||
*/
|
||||
public WordDocumentProperties() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a document
|
||||
*
|
||||
* @param filename
|
||||
*/
|
||||
public void open(String filename) {
|
||||
//Instantiate objWord
|
||||
objWord = new ActiveXComponent("Word.Application");
|
||||
|
||||
//Assign a local word object
|
||||
wordObject = objWord.getObject();
|
||||
|
||||
//Create a Dispatch Parameter to hide the document that is opened
|
||||
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(false));
|
||||
|
||||
//Instantiate the Documents Property
|
||||
Dispatch documents = objWord.getProperty("Documents").toDispatch();
|
||||
|
||||
//Open a word document, Current Active Document
|
||||
document = Dispatch.call(documents, "Open", filename).toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA CustomDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectCustomDocumentProperitiesMode() {
|
||||
//Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
custDocprops = Dispatch.get(document, "CustomDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA BuiltInDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectBuiltinPropertiesMode() {
|
||||
//Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a document
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
//Close object
|
||||
Dispatch.call(document, "Close");
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Property Name is passed in
|
||||
*
|
||||
* @param cusPropName
|
||||
* @return String - Custom property value
|
||||
*/
|
||||
public String getCustomProperty(String cusPropName) {
|
||||
try {
|
||||
cusPropName = Dispatch.call((Dispatch) custDocprops, "Item",
|
||||
cusPropName).toString();
|
||||
} catch (ComFailException e) {
|
||||
// Do nothing
|
||||
cusPropName = null;
|
||||
}
|
||||
|
||||
return cusPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Built In Property Name is passed in
|
||||
*
|
||||
* @param builtInPropName
|
||||
* @return String - Built in property value
|
||||
*/
|
||||
public String getBuiltInProperty(String builtInPropName) {
|
||||
try {
|
||||
builtInPropName = Dispatch.call((Dispatch) builtInDocProps, "Item",
|
||||
builtInPropName).toString();
|
||||
} catch (ComFailException e) {
|
||||
// Do nothing
|
||||
builtInPropName = null;
|
||||
}
|
||||
|
||||
return builtInPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* simple main program that gets some properties and prints them out
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//Instantiate the class
|
||||
WordDocumentProperties jacTest = new WordDocumentProperties();
|
||||
|
||||
//Open the word doc
|
||||
jacTest.open("\\\\Saturn\\documentstorage\\s.doc");
|
||||
|
||||
//Set Custom Properties
|
||||
jacTest.selectCustomDocumentProperitiesMode();
|
||||
|
||||
//Set Built In Properties
|
||||
jacTest.selectBuiltinPropertiesMode();
|
||||
|
||||
//Get custom Property Value
|
||||
String custValue = jacTest.getCustomProperty("Information Source");
|
||||
|
||||
//Get built in prroperty Property Value
|
||||
String builtInValue = jacTest.getBuiltInProperty("Author");
|
||||
|
||||
//Close Word Doc
|
||||
jacTest.close();
|
||||
|
||||
//Output data
|
||||
System.out.println("Document Val One: " + custValue);
|
||||
System.out.println("Document Author: " + builtInValue);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
This sample runs in Weblogic 5.1 as a servlet.
|
||||
|
||||
0. Rename JacobScript.java_nocompile to JacobScript.java
|
||||
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
|
||||
|
||||
@@ -2,12 +2,15 @@ package com.jacob.samples.test;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
/*
|
||||
/**
|
||||
* This demonstrates the new event handling code in jacob 1.7
|
||||
* This example will open up IE and print out some of the events
|
||||
* it listens to as it havigates to web sites.
|
||||
* contributed by Niels Olof Bouvin mailto:n.o.bouvin@daimi.au.dk
|
||||
* and Henning Jae jehoej@daimi.au.dk
|
||||
* <P>
|
||||
* You can run this in eclipse with the command line options
|
||||
* <code> -Djava.library.path=d:/jacob/release -Dcom.jacob.autogc=false </code>
|
||||
*/
|
||||
|
||||
class IETest
|
||||
@@ -15,14 +18,14 @@ class IETest
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// this line starts the pump but it runs fine without it
|
||||
//ComThread.startMainSTA();
|
||||
ComThread.startMainSTA();
|
||||
// remove this line and it dies
|
||||
ComThread.InitMTA(true);
|
||||
///ComThread.InitMTA(true);
|
||||
IETestThread aThread = new IETestThread();
|
||||
aThread.run();
|
||||
aThread.start();
|
||||
while (aThread.isAlive()){
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// doen with the sleep
|
||||
//e.printStackTrace();
|
||||
@@ -37,13 +40,15 @@ class IETest
|
||||
|
||||
class IETestThread extends Thread
|
||||
{
|
||||
public static boolean quitHandled = false;
|
||||
|
||||
public IETestThread(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
int delay = 5000; // msec
|
||||
int delay = 5000; // msec
|
||||
// paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent("InternetExplorer.Application");
|
||||
@@ -54,7 +59,7 @@ class IETestThread extends Thread
|
||||
Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
|
||||
IEEvents ieE = new IEEvents();
|
||||
DispatchEvents de = new DispatchEvents((Dispatch) ie, ieE,"InternetExplorer.Application.1");
|
||||
new DispatchEvents((Dispatch) ie, ieE,"InternetExplorer.Application.1");
|
||||
Variant optional = new Variant();
|
||||
optional.noParam();
|
||||
|
||||
@@ -72,82 +77,97 @@ class IETestThread extends Thread
|
||||
// "OnQuit" that will came after we have released the thread pool
|
||||
// this is probably messed up because DispatchEvent object will have been
|
||||
// freed before the callback
|
||||
System.out.println("about to call release in thread");
|
||||
// commenting out ie.invoke(quit...) causes this to work without error
|
||||
// this code tries to wait until the quit has been handled but that doesn't work
|
||||
System.out.println("IETest: Waiting until we've received the quit callback");
|
||||
while (!quitHandled){
|
||||
try { Thread.sleep(delay/5);} catch (InterruptedException e) {}
|
||||
}
|
||||
// wait a little while for it to end
|
||||
try {Thread.sleep(delay); } catch (InterruptedException e) {}
|
||||
System.out.println("IETest: about to call release in thread " +
|
||||
Thread.currentThread().getName());
|
||||
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
|
||||
class IEEvents
|
||||
/**
|
||||
* the events class must be publicly accessable for reflection to work
|
||||
*/
|
||||
public class IEEvents
|
||||
{
|
||||
public void BeforeNavigate2(Variant[] args) {
|
||||
System.out.println("BeforeNavigate2");
|
||||
System.out.println("IEEvents: BeforeNavigate2");
|
||||
}
|
||||
|
||||
public void CommandStateChanged(Variant[] args) {
|
||||
System.out.println("CommandStateChanged");
|
||||
public void CommandStateChange(Variant[] args) {
|
||||
System.out.println("IEEvents: CommandStateChange");
|
||||
}
|
||||
|
||||
public void DocumentComplete(Variant[] args) {
|
||||
System.out.println("DocumentComplete");
|
||||
System.out.println("IEEvents: DocumentComplete");
|
||||
}
|
||||
|
||||
public void DownloadBegin(Variant[] args) {
|
||||
System.out.println("DownloadBegin");
|
||||
System.out.println("IEEvents: DownloadBegin");
|
||||
}
|
||||
|
||||
public void DownloadComplete(Variant[] args) {
|
||||
System.out.println("DownloadComplete");
|
||||
System.out.println("IEEvents: DownloadComplete");
|
||||
}
|
||||
|
||||
public void NavigateComplete2(Variant[] args) {
|
||||
System.out.println("NavigateComplete2");
|
||||
System.out.println("IEEvents: NavigateComplete2");
|
||||
}
|
||||
|
||||
public void NewWindow2(Variant[] args) {
|
||||
System.out.println("NewWindow2");
|
||||
System.out.println("IEEvents: NewWindow2");
|
||||
}
|
||||
|
||||
public void OnFullScreen(Variant[] args) {
|
||||
System.out.println("OnFullScreen");
|
||||
System.out.println("IEEvents: OnFullScreen");
|
||||
}
|
||||
|
||||
public void OnMenuBar(Variant[] args) {
|
||||
System.out.println("OnMenuBar");
|
||||
System.out.println("IEEvents: OnMenuBar");
|
||||
}
|
||||
|
||||
public void OnQuit(Variant[] args) {
|
||||
System.out.println("OnQuit");
|
||||
System.out.println("IEEvents: OnQuit");
|
||||
IETestThread.quitHandled = true;
|
||||
}
|
||||
|
||||
public void OnStatusBar(Variant[] args) {
|
||||
System.out.println("OnStatusBar");
|
||||
System.out.println("IEEvents: OnStatusBar");
|
||||
}
|
||||
|
||||
public void OnTheaterMode(Variant[] args) {
|
||||
System.out.println("OnTheaterMode");
|
||||
System.out.println("IEEvents: OnTheaterMode");
|
||||
}
|
||||
|
||||
public void OnToolBar(Variant[] args) {
|
||||
System.out.println("OnToolBar");
|
||||
System.out.println("IEEvents: OnToolBar");
|
||||
}
|
||||
|
||||
public void OnVisible(Variant[] args) {
|
||||
System.out.println("OnVisible");
|
||||
System.out.println("IEEvents: OnVisible");
|
||||
}
|
||||
|
||||
public void ProgressChange(Variant[] args) {
|
||||
System.out.println("ProgressChange");
|
||||
System.out.println("IEEvents: ProgressChange");
|
||||
}
|
||||
|
||||
public void PropertyChange(Variant[] args) {
|
||||
System.out.println("PropertyChange");
|
||||
System.out.println("IEEvents: PropertyChange");
|
||||
}
|
||||
|
||||
public void StatusTextChange(Variant[] args) {
|
||||
System.out.println("StatusTextChange");
|
||||
System.out.println("IEEvents: StatusTextChange");
|
||||
}
|
||||
|
||||
public void TitleChange(Variant[] args) {
|
||||
System.out.println("TitleChange");
|
||||
System.out.println("IEEvents: TitleChange");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ class ScriptTest
|
||||
Dispatch.put(sControl, "Language", lang);
|
||||
ScriptTestErrEvents te = new ScriptTestErrEvents();
|
||||
de = new DispatchEvents(sControl, te);
|
||||
if (de == null){
|
||||
System.out.println("Received null when trying to create new DispatchEvents");
|
||||
}
|
||||
Variant result = Dispatch.call(sControl, "Eval", args[0]);
|
||||
// call it twice to see the objects reused
|
||||
result = Dispatch.call(sControl, "Eval", args[0]);
|
||||
|
||||
@@ -20,6 +20,9 @@ class ScriptTestActiveX
|
||||
sC.setProperty("Language",lang);
|
||||
ScriptTestErrEvents te = new ScriptTestErrEvents();
|
||||
de = new DispatchEvents(sC, te);
|
||||
if (de == null){
|
||||
System.out.println("null returned when trying to create DispatchEvents");
|
||||
}
|
||||
Variant result;
|
||||
result = sC.invoke("Eval",args[0]);
|
||||
// call it twice to see the objects reused
|
||||
|
||||
@@ -3,32 +3,35 @@ package com.jacob.samples.test.atl;
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
|
||||
class MultiFaceTest
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.runFinalizersOnExit(true);
|
||||
class MultiFaceTest {
|
||||
public static void main(String[] args) {
|
||||
// this method has been deprecated as being unreliable.
|
||||
// shutdown should be done through other means
|
||||
// whoever wrote this example should explain what this was intended to do
|
||||
//System.runFinalizersOnExit(true);
|
||||
|
||||
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
|
||||
try {
|
||||
// I am now dealing with the default interface (IFace1)
|
||||
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
|
||||
System.out.println(Dispatch.get(mf, "Face1Name"));
|
||||
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
|
||||
try {
|
||||
// I am now dealing with the default interface (IFace1)
|
||||
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
|
||||
System.out.println(Dispatch.get(mf, "Face1Name"));
|
||||
|
||||
// get to IFace2 through the IID
|
||||
Dispatch f2 = mf.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace2
|
||||
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
|
||||
System.out.println(Dispatch.get(f2, "Face2Nam"));
|
||||
// get to IFace2 through the IID
|
||||
Dispatch f2 = mf
|
||||
.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace2
|
||||
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
|
||||
System.out.println(Dispatch.get(f2, "Face2Nam"));
|
||||
|
||||
// get to IFace3 through the IID
|
||||
Dispatch f3 = mf.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace3
|
||||
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
|
||||
System.out.println(Dispatch.get(f3, "Face3Name"));
|
||||
// get to IFace3 through the IID
|
||||
Dispatch f3 = mf
|
||||
.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace3
|
||||
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
|
||||
System.out.println(Dispatch.get(f3, "Face3Name"));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,46 @@
|
||||
package com.jacob.samples.test;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.*;
|
||||
|
||||
/*
|
||||
/**
|
||||
* This example uses the MathTest sample VB COM DLL under
|
||||
* the MathProj directory
|
||||
* <pre>
|
||||
* -Djava.library.path=d:/jacob/release -Dcom.jacob.autogc=false -Dcom.jacob.debug=true
|
||||
* </pre>
|
||||
*/
|
||||
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));
|
||||
class math {
|
||||
public static void main(String[] args) {
|
||||
// deprecated
|
||||
// System.runFinalizersOnExit(true);
|
||||
Dispatch test = new ActiveXComponent("MathTest.Math");
|
||||
testEvents te = new testEvents();
|
||||
DispatchEvents de = new DispatchEvents(test, te);
|
||||
if (de == null) {
|
||||
System.out
|
||||
.println("null returned when trying to create DispatchEvents");
|
||||
}
|
||||
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");
|
||||
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());
|
||||
}
|
||||
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");
|
||||
}
|
||||
public void DoneAdd(Variant[] args) {
|
||||
System.out.println("DoneAdd called in java");
|
||||
}
|
||||
|
||||
public void DoneMult(Variant[] args) {
|
||||
System.out.println("DoneMult called in java");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import com.jacob.activeX.*;
|
||||
|
||||
class sa_dispatch
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.runFinalizersOnExit(true);
|
||||
public static void main(String args[])
|
||||
{
|
||||
// deprecated
|
||||
//System.runFinalizersOnExit(true);
|
||||
|
||||
try {
|
||||
String lang = "VBScript";
|
||||
|
||||
@@ -2,57 +2,97 @@ 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);
|
||||
/**
|
||||
* SafeArrayTest Program
|
||||
*
|
||||
* This is more of an exerciser. It doesn't verify that it gets back
|
||||
* what it expects like a junit test would
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
sa_ND_test();
|
||||
|
||||
}
|
||||
|
||||
public static void sa_ND_test() {
|
||||
int[] lowerBounds = new int[] { 0, 0, 0 };
|
||||
int[] dimensionSizes = new int[] { 3, 3, 3 };
|
||||
|
||||
SafeArray sa3x3 = new SafeArray(Variant.VariantVariant, lowerBounds,
|
||||
dimensionSizes);
|
||||
|
||||
System.out.println("Num Dimensions = " + sa3x3.getNumDim());
|
||||
for (int i = 1; i <= sa3x3.getNumDim(); i++) {
|
||||
System.out.println("Dimension number = " + i);
|
||||
System.out.println("Lower bound = " + sa3x3.getLBound(i));
|
||||
System.out.println("Upper bound = " + sa3x3.getUBound(i));
|
||||
}
|
||||
|
||||
int fill = 0;
|
||||
int[] indices = new int[] { 0, 0, 0 };
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
indices[0] = i;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
indices[1] = j;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
indices[2] = k;
|
||||
fill = i * 100 + j * 10 + k;
|
||||
sa3x3.setInt(indices, fill);
|
||||
System.out.println("sa[" + i + "][" + j + "][" + k + "] = "
|
||||
+ sa3x3.getInt(indices));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,12 @@ public class safearray
|
||||
{
|
||||
public static void main(java.lang.String[] args)
|
||||
{
|
||||
System.runFinalizersOnExit(true);
|
||||
//deprecated
|
||||
//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");
|
||||
@@ -30,7 +29,6 @@ public class safearray
|
||||
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++)
|
||||
{
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
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());
|
||||
}
|
||||
class variant_test {
|
||||
public static void main(String[] args) {
|
||||
//deprecated
|
||||
//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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user