/* HEADER */ import org.apache.log4j.BasicConfigurator; import org.eclipse.swt.SWT; import org.eclipse.swt.ole.win32.OleAutomation; import org.eclipse.swt.ole.win32.OleControlSite; import org.eclipse.swt.ole.win32.OleFrame; import org.eclipse.swt.ole.win32.Variant; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** * @author brett */ public class ServerXTest { void startServer(Shell shell, String password) throws Exception { System.out.println("Creating Ole frame"); new Label(shell, SWT.NONE).setText("Hello!"); OleFrame frame = new OleFrame(shell, SWT.NONE); OleControlSite site = null; OleAutomation auto = null; String progID = "SmartCode.ServerX"; System.out.println("Creating Ole site"); site = new OleControlSite(frame, SWT.NONE, progID); System.out.println("Creating Ole automation"); auto = new OleAutomation(site); System.out.println("Setting password"); auto.setProperty(auto.getIDsOfNames(new String[] { "Password" })[0], new Variant(password)); // Get ids int portId = auto.getIDsOfNames(new String[] { "Port" })[0]; int allowConnectionsId = auto.getIDsOfNames(new String[] { "AllowConnections" })[0]; int showTrayIconId = auto.getIDsOfNames(new String[] { "ShowTrayIcon" })[0]; int addClientId = auto.getIDsOfNames(new String[] { "AddClient" })[0]; int startId = auto.getIDsOfNames(new String[] { "Start" })[0]; // Set properties auto.setProperty(portId, new Variant(5910)); auto.setProperty(allowConnectionsId, new Variant(true)); auto.setProperty(showTrayIconId, new Variant(true)); // Dump them back out again System.out.println("Port set to " + auto.getProperty(portId)); System.out.println("AllowConnections set to " + auto.getProperty(allowConnectionsId)); System.out.println("ShowTrayIcon set to " + auto.getProperty(showTrayIconId)); // Connect // System.out.println("Adding client"); // Variant result = auto.invoke(addClientId, new Variant[] { new // Variant("blue.southpark.net"), new Variant(5910) }); // if(result == null) { // throw new RemoteAssistanceUserException("Null result from adding // client"); // } // System.out.println("Added client"); System.out.println("Server started - " + auto.invoke(startId)); } /** * Test Ebtry point. * * @param args arguments * @throws Exception on any errors */ public static void main(String[] args) throws Exception { BasicConfigurator.configure(); ServerXTest s = new ServerXTest(); Display display = Display.getDefault(); Shell shell = new Shell(display); shell.setVisible(true); s.startServer(shell, "5h3113d"); while (true) { if (!display.readAndDispatch()) display.sleep(); } } }