diff --git a/.classpath b/.classpath index 3383917d0a..d7b6c52328 100644 --- a/.classpath +++ b/.classpath @@ -5,5 +5,6 @@ + diff --git a/CHANGES.md b/CHANGES.md index fae7c2d78b..c36e1a1164 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,10 @@ Release 4.2 Features -------- +* Significant enhancements to COM support under com.sun.jna.platform.win32.COM.util - [@dhakehurst](https://github.com/dhakehurst). + * Use of interfaces and annotations to provide easier implementation of COM interfaces (uses InvocationHandler) - [@dhakehurst](https://github.com/dhakehurst). + * Support for COM event callbacks (this was particularly tricky, very happy I got it to work) - [@dhakehurst](https://github.com/dhakehurst). + * Support for COM interface discovery by iteration over the RunningObjectTable - [@dhakehurst](https://github.com/dhakehurst). * Updated AIX natives and build - [@twall](https://github.com/twall). * [#290](https://github.com/twall/jna/pull/290): Improved the stacktrace for the exceptions thrown by `com.sun.jna.Structure` - [@ebourg](https://github.com/ebourg). * [#332](https://github.com/twall/jna/pull/332): Added Win32 Monitor Configuration API in `com.sun.jna.platform.win32.Dxva2` - [@msteiger](https://github.com/msteiger). diff --git a/contrib/msoffice/.classpath b/contrib/msoffice/.classpath index 8648c074a2..34c74501c1 100644 --- a/contrib/msoffice/.classpath +++ b/contrib/msoffice/.classpath @@ -2,7 +2,7 @@ - - + + diff --git a/contrib/msoffice/jnatest.xls b/contrib/msoffice/jnatest.xls index 8da722704c..6077e40a43 100644 Binary files a/contrib/msoffice/jnatest.xls and b/contrib/msoffice/jnatest.xls differ diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.java index 49967d4374..f4d6658cbd 100644 --- a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.java +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.java @@ -18,8 +18,8 @@ public static void main(String[] args) { + File.separator; public MSOfficeDemo() { - this.testMSWord(); - // this.testMSExcel(); + //this.testMSWord(); + this.testMSExcel(); } public void testMSWord() { diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeExcelDemo.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeExcelDemo.java new file mode 100644 index 0000000000..a7a49b7d06 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeExcelDemo.java @@ -0,0 +1,100 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office; + +import java.io.File; + +import com.sun.jna.platform.win32.COM.office.MSExcel; +import com.sun.jna.platform.win32.COM.util.AbstractComEventCallbackListener; +import com.sun.jna.platform.win32.COM.util.Factory; +import com.sun.jna.platform.win32.COM.util.office.excel.ComExcel_Application; +import com.sun.jna.platform.win32.COM.util.office.excel.ComIAppEvents; +import com.sun.jna.platform.win32.COM.util.office.excel.ComIApplication; +import com.sun.jna.platform.win32.COM.util.office.excel.ComIRange; +import com.sun.jna.platform.win32.COM.util.office.excel.ComIWorksheet; +import com.sun.jna.platform.win32.COM.util.office.word.ComWord_Application; + +public class MSOfficeExcelDemo { + + /** + * @param args + */ + public static void main(String[] args) { + new MSOfficeExcelDemo(); + } + + private String currentWorkingDir = new File("").getAbsolutePath() + File.separator; + + public MSOfficeExcelDemo() { + this.testMSExcel(); + } + + public void testMSExcel() { + ComExcel_Application excelObject = null; + ComIApplication msExcel = null; + Factory factory = null; + try { + factory = new Factory(); + excelObject = factory.createObject(ComExcel_Application.class); + msExcel = excelObject.queryInterface(ComIApplication.class); + System.out.println("MSExcel version: " + msExcel.getVersion()); + msExcel.setVisible(true); + // msExcel.newExcelBook(); + msExcel.getWorkbooks().Open(currentWorkingDir + "jnatest.xls"); + msExcel.getActiveSheet().getRange("A1").setValue("Hello from JNA!"); + // wait 1sec. before closing + Thread.currentThread().sleep(1000); +// // close and save the active sheet +// msExcel.getActiveWorkbook().Close(true); +// msExcel.setVisible(true); +// // msExcel.newExcelBook(); +// msExcel.getWorkbooks().Open(currentWorkingDir + "jnatest.xls"); +// msExcel.getActiveSheet().getRange("A2").setValue("Hello again from JNA!"); + + class Listener extends AbstractComEventCallbackListener implements ComIAppEvents { + boolean SheetSelectionChange_called; + + @Override + public void errorReceivingCallbackEvent(String message, Exception exception) { + } + + @Override + public void SheetSelectionChange(ComIWorksheet sheet, ComIRange target) { + SheetSelectionChange_called = true; + } + + }; + Listener listener = new Listener(); + msExcel.advise(ComIAppEvents.class, listener); +// +// msExcel.getActiveSheet().getRange("A5").Activate(); +// +// Thread.currentThread().sleep(500); + + // close and save the active sheet + msExcel.getActiveWorkbook().Close(true); + + msExcel.Quit(); + msExcel = null; + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (null != msExcel) { + msExcel.Quit(); + } + if (null != factory) { + factory.disposeAll(); + } + } + } +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeWordDemo.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeWordDemo.java new file mode 100644 index 0000000000..f03467993f --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/MSOfficeWordDemo.java @@ -0,0 +1,109 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office; + +import java.io.File; + +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.util.Factory; +import com.sun.jna.platform.win32.COM.util.office.word.ComIApplication; +import com.sun.jna.platform.win32.COM.util.office.word.ComWord_Application; +import com.sun.jna.platform.win32.COM.util.office.word.WdOriginalFormat; +import com.sun.jna.platform.win32.COM.util.office.word.WdSaveFormat; + +public class MSOfficeWordDemo { + + /** + * @param args + */ + public static void main(String[] args) { + new MSOfficeWordDemo(); + } + + private String currentWorkingDir = new File("").getAbsolutePath() + File.separator; + + public MSOfficeWordDemo() { + this.testMSWord(); + } + + public void testMSWord() { + ComWord_Application msWordObject = null; + ComIApplication msWord = null; + Factory factory = null; + try { + String tempDir = System.getProperty("java.io.tmpdir"); + System.out.println("Files in temp dir: "+tempDir); + + factory = new Factory(); + msWordObject = factory.createObject(ComWord_Application.class); + msWord = msWordObject.queryInterface(ComIApplication.class); + + System.out.println("MSWord version: " + msWord.getVersion()); + + msWord.setVisible(true); + // msWord.newDocument(); + msWord.getDocuments().Open(currentWorkingDir + "jnatest.doc"); + msWord.getSelection().TypeText("Hello from JNA! \n\n"); + // wait 10sec. before closing + Thread.sleep(1000); + // save in different formats + // pdf format is only supported in MSWord 2007 and above + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestSaveAs.doc", WdSaveFormat.wdFormatDocument); + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestSaveAs.pdf", WdSaveFormat.wdFormatPDF); + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestSaveAs.rtf", WdSaveFormat.wdFormatRTF); + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestSaveAs.html", WdSaveFormat.wdFormatHTML); + // close and save the document + msWord.getActiveDocument().Close(false); + msWord.getDocuments().Add(); + // msWord.openDocument(currentWorkingDir + "jnatest.doc", true); + msWord.getSelection() + .TypeText( + "Hello from JNA! \n Please notice that JNA can control MS Word via the new COM interface! \nHere we are creating a new word document and we save it to the 'TEMP' directory!"); + // save with no user prompt + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestNewDoc1.docx", WdSaveFormat.wdFormatDocumentDefault); + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestNewDoc2.docx", WdSaveFormat.wdFormatDocumentDefault); + msWord.getActiveDocument().SaveAs(tempDir+"\\jnatestNewDoc3.docx", WdSaveFormat.wdFormatDocumentDefault); + // close and save the document + msWord.getActiveDocument().Close(false); + // open 3 documents + msWord.getDocuments().Open(tempDir+"\\jnatestNewDoc1.docx"); + msWord.getSelection().TypeText("Hello some changes from JNA!\n"); + msWord.getDocuments().Open(tempDir+"\\jnatestNewDoc2.docx"); + msWord.getSelection().TypeText("Hello some changes from JNA!\n"); + msWord.getDocuments().Open(tempDir+"\\jnatestNewDoc3.docx"); + msWord.getSelection().TypeText("Hello some changes from JNA!\n"); + // save the document and prompt the user + msWord.getDocuments().Save(false, WdOriginalFormat.wdPromptUser); + // wait then close word + msWord.Quit(); + msWord = null; + } catch (InterruptedException ie) { + ie.printStackTrace(); + } catch (COMException e) { + if (e.getExcepInfo() != null) { + System.out.println("bstrSource: " + e.getExcepInfo().bstrSource); + System.out.println("bstrDescription: " + e.getExcepInfo().bstrDescription); + } + + // print stack trace + e.printStackTrace(); + } finally { + if (msWord != null) { + msWord.Quit(); + } + if (null != factory) { + factory.getComThread().terminate(500); + } + } + } +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComExcel_Application.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComExcel_Application.java new file mode 100644 index 0000000000..07cc479b48 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComExcel_Application.java @@ -0,0 +1,10 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.IUnknown; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; + +@ComObject(progId="Excel.Application") +public interface ComExcel_Application extends IUnknown { + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIAppEvents.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIAppEvents.java new file mode 100644 index 0000000000..381abef705 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIAppEvents.java @@ -0,0 +1,12 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.annotation.ComEventCallback; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; + +@ComInterface(iid="{00024413-0000-0000-C000-000000000046}") +public interface ComIAppEvents { + + @ComEventCallback(dispid=1558) + public void SheetSelectionChange(ComIWorksheet sheet, ComIRange target); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIApplication.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIApplication.java new file mode 100644 index 0000000000..11f7cec543 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIApplication.java @@ -0,0 +1,32 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.IConnectionPoint; +import com.sun.jna.platform.win32.COM.util.IUnknown; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +@ComInterface(iid="{000208D5-0000-0000-C000-000000000046}") +public interface ComIApplication extends IUnknown, IConnectionPoint { + + @ComProperty + String getVersion(); + + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComProperty + ComIWorkbooks getWorkbooks(); + + @ComProperty + ComIWorksheet getActiveSheet(); + + @ComProperty + ComIWorkbook getActiveWorkbook(); + + @ComMethod + void Quit(); +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIRange.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIRange.java new file mode 100644 index 0000000000..4d79f20f44 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIRange.java @@ -0,0 +1,25 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +@ComInterface(iid = "{00020846-0000-0000-C000-000000000046}") +public interface ComIRange { + + @ComProperty + ComIApplication getApplication(); + + @ComProperty + String getText(); + + @ComMethod + void Select(); + + @ComProperty + void setValue(String value); + + @ComMethod + void Activate(); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbook.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbook.java new file mode 100644 index 0000000000..375a684510 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbook.java @@ -0,0 +1,13 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; + +@ComInterface(iid="{0002096B-0000-0000-C000-000000000046}") +public interface ComIWorkbook { + + @ComMethod + void Close(boolean saveChanges); + + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbooks.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbooks.java new file mode 100644 index 0000000000..c9174c23c2 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorkbooks.java @@ -0,0 +1,19 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +@ComInterface(iid = "{000208DB-0000-0000-C000-000000000046}") +public interface ComIWorkbooks { + + @ComProperty + long getCount(); + + @ComMethod + ComIWorkbook Item(long index); + + @ComMethod + ComIWorkbook Open(Object FileName); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorksheet.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorksheet.java new file mode 100644 index 0000000000..2687f80d27 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/excel/ComIWorksheet.java @@ -0,0 +1,19 @@ +package com.sun.jna.platform.win32.COM.util.office.excel; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +@ComInterface(iid="{000208D8-0000-0000-C000-000000000046}") +public interface ComIWorksheet { + + @ComProperty + String getName(); + + @ComProperty + ComIRange getRange(String cell1); + + @ComProperty + ComIApplication getApplication(); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIApplication.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIApplication.java new file mode 100644 index 0000000000..10a18b21e8 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIApplication.java @@ -0,0 +1,43 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +@ComInterface(iid="{00020970-0000-0000-C000-000000000046}") +public interface ComIApplication { + + @ComProperty + String getVersion(); + + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComProperty + ComIDocuments getDocuments(); + + @ComProperty + ComISelection getSelection(); + + @ComProperty + ComIDocument getActiveDocument(); + + @ComMethod + void Quit(); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocument.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocument.java new file mode 100644 index 0000000000..e370130b8e --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocument.java @@ -0,0 +1,25 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; + +public interface ComIDocument { + + @ComMethod + void SaveAs(String string, WdSaveFormat wdFormatDocument); + + @ComMethod + void Close(boolean saveChanges); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocuments.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocuments.java new file mode 100644 index 0000000000..2096de5af5 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComIDocuments.java @@ -0,0 +1,28 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; + +public interface ComIDocuments { + + @ComMethod + ComIDocument Open(String fileName); + + @ComMethod + ComIDocument Add(); + + @ComMethod + void Save(boolean noPrompt, WdOriginalFormat originalFormat); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComISelection.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComISelection.java new file mode 100644 index 0000000000..53d59b4f90 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComISelection.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; + +@ComInterface +public interface ComISelection { + + @ComMethod + void TypeText(String text); + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComWord_Application.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComWord_Application.java new file mode 100644 index 0000000000..af7a26e2d9 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/ComWord_Application.java @@ -0,0 +1,21 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.IUnknown; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; + +@ComObject(progId="Word.Application") +public interface ComWord_Application extends IUnknown { + +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdOriginalFormat.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdOriginalFormat.java new file mode 100644 index 0000000000..b7f4bbee46 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdOriginalFormat.java @@ -0,0 +1,29 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.IComEnum; + +public enum WdOriginalFormat implements IComEnum { + wdOriginalDocumentFormat(1), // Original document format. + wdPromptUser(2), // Prompt user to select a document format. + wdWordDocument(0); // Microsoft Word document format. + + private WdOriginalFormat(long value) { + this.value = value; + } + private long value; + public long getValue() { + return this.value; + } +} diff --git a/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdSaveFormat.java b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdSaveFormat.java new file mode 100644 index 0000000000..7b7fce9fb1 --- /dev/null +++ b/contrib/msoffice/src/com/sun/jna/platform/win32/COM/util/office/word/WdSaveFormat.java @@ -0,0 +1,54 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.office.word; + +import com.sun.jna.platform.win32.COM.util.IComEnum; + +public enum WdSaveFormat implements IComEnum { + wdFormatDocument(0), // Microsoft Office Word 97 - 2003 binary file format. + wdFormatDOSText(4), // Microsoft DOS text format. + wdFormatDOSTextLineBreaks(5), // Microsoft DOS text with line breaks preserved. + wdFormatEncodedText(7), // Encoded text format. + wdFormatFilteredHTML(10), // Filtered HTML format. + wdFormatFlatXML(19), // Open XML file format saved as a single XML file. + wdFormatFlatXMLMacroEnabled(20), // Open XML file format with macros enabled saved as a single XML file. + wdFormatFlatXMLTemplate(21), // Open XML template format saved as a XML single file. + wdFormatFlatXMLTemplateMacroEnabled(22), // Open XML template format with macros enabled saved as a single XML file. + wdFormatOpenDocumentText(23), // OpenDocument Text format. + wdFormatHTML(8), // Standard HTML format. + wdFormatRTF(6), // Rich text format (RTF). + wdFormatStrictOpenXMLDocument(24), // Strict Open XML document format. + wdFormatTemplate(1), // Word template format. + wdFormatText(2), // Microsoft Windows text format. + wdFormatTextLineBreaks(3), //Windows text format with line breaks preserved. + wdFormatUnicodeText( 7), //Unicode text format. + wdFormatWebArchive(9), //Web archive format. + wdFormatXML(11), //Extensible Markup Language (XML) format. + wdFormatDocument97( 0), // Microsoft Word 97 document format. + wdFormatDocumentDefault(16), // Word default document file format. For Word 2010, this is the DOCX format. + wdFormatPDF( 17), //PDF format. + wdFormatTemplate97( 1), // Word 97 template format. + wdFormatXMLDocument( 12), //XML document format. + wdFormatXMLDocumentMacroEnabled(13), //XML document format with macros enabled. + wdFormatXMLTemplate(14), //XML template format. + wdFormatXMLTemplateMacroEnabled(15), //XML template format with macros enabled. + wdFormatXPS(18); + + private WdSaveFormat(long value) { + this.value = value; + } + private long value; + public long getValue() { + return this.value; + } +} diff --git a/contrib/platform/.classpath b/contrib/platform/.classpath index 91a28a2ee6..77917d7b3f 100644 --- a/contrib/platform/.classpath +++ b/contrib/platform/.classpath @@ -2,9 +2,8 @@ - - - + + diff --git a/contrib/platform/.project b/contrib/platform/.project index eb21a1889c..2cad830e2f 100644 --- a/contrib/platform/.project +++ b/contrib/platform/.project @@ -1,6 +1,6 @@ - platform + com.sun.jna.platform diff --git a/contrib/platform/.settings/org.eclipse.jdt.core.prefs b/contrib/platform/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..54e493c07c --- /dev/null +++ b/contrib/platform/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java index eddbbd48f8..35237c1182 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java @@ -15,6 +15,7 @@ import com.sun.jna.WString; import com.sun.jna.platform.win32.Guid; import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.OaIdl; import com.sun.jna.platform.win32.OaIdl.DISPID; @@ -26,6 +27,7 @@ import com.sun.jna.platform.win32.Variant.VARIANT; import com.sun.jna.platform.win32.Variant.VariantArg; import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinNT.HRESULT; @@ -85,7 +87,7 @@ public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance, if (COMUtils.SUCCEEDED(hr)) { this.iUnknown = new Unknown(this.pUnknown.getValue()); - hr = iUnknown.QueryInterface(IDispatch.IID_IDISPATCH, + hr = iUnknown.QueryInterface(new REFIID.ByValue( IDispatch.IID_IDISPATCH), this.pDispatch); } else { hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, @@ -130,7 +132,7 @@ public COMBindingBaseObject(String progId, boolean useActiveInstance, if (COMUtils.SUCCEEDED(hr)) { this.iUnknown = new Unknown(this.pUnknown.getValue()); - hr = iUnknown.QueryInterface(IDispatch.IID_IDISPATCH, + hr = iUnknown.QueryInterface(new REFIID.ByValue(IDispatch.IID_IDISPATCH), this.pDispatch); } else { hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, @@ -212,7 +214,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, DISPIDByReference pdispID = new DISPIDByReference(); // Get DISPID for name passed... - HRESULT hr = pDisp.GetIDsOfNames(Guid.IID_NULL, ptName, 1, + HRESULT hr = pDisp.GetIDsOfNames(new REFIID.ByValue(Guid.IID_NULL), ptName, 1, LOCALE_USER_DEFAULT, pdispID); COMUtils.checkRC(hr); @@ -231,7 +233,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, // variable declaration int _argsLen = 0; VARIANT[] _args = null; - DISPPARAMS dp = new DISPPARAMS(); + DISPPARAMS.ByReference dp = new DISPPARAMS.ByReference(); EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference(); IntByReference puArgErr = new IntByReference(); @@ -264,8 +266,8 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, } // Make the call! - HRESULT hr = pDisp.Invoke(dispId, Guid.IID_NULL, LOCALE_SYSTEM_DEFAULT, - new DISPID(nType), dp, pvResult, pExcepInfo, puArgErr); + HRESULT hr = pDisp.Invoke(dispId, new REFIID.ByValue(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, + new WinDef.WORD(nType), dp, pvResult, pExcepInfo, puArgErr); COMUtils.checkRC(hr, pExcepInfo, puArgErr); return hr; diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMEarlyBindingObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMEarlyBindingObject.java index 07220e0d4a..34a23b50e8 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMEarlyBindingObject.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMEarlyBindingObject.java @@ -15,6 +15,7 @@ import com.sun.jna.WString; import com.sun.jna.platform.win32.Guid.CLSID; import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.OaIdl.DISPID; import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; @@ -25,6 +26,7 @@ import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; @@ -57,7 +59,7 @@ protected void setProperty(DISPID dispId, boolean value) { } @Override - public HRESULT QueryInterface(IID riid, PointerByReference ppvObject) { + public HRESULT QueryInterface(REFIID.ByValue riid, PointerByReference ppvObject) { return this.getIDispatch().QueryInterface(riid, ppvObject); } @@ -83,16 +85,16 @@ public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, } @Override - public HRESULT GetIDsOfNames(IID riid, WString[] rgszNames, int cNames, + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, DISPIDByReference rgDispId) { return this.getIDispatch().GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId); } @Override - public HRESULT Invoke(DISPID dispIdMember, IID riid, LCID lcid, - DISPID wFlags, DISPPARAMS pDispParams, ByReference pVarResult, - EXCEPINFO.ByReference pExcepInfo, + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, + WORD wFlags, DISPPARAMS.ByReference pDispParams, + VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, IntByReference puArgErr) { return this.getIDispatch().Invoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMException.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMException.java index eefc7d6c26..8431a63733 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMException.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMException.java @@ -72,7 +72,7 @@ public COMException(String message) { */ public COMException(String message, EXCEPINFO pExcepInfo, IntByReference puArgErr) { - super(message + " (puArgErr=" + puArgErr.getValue() + ")"); + super(message + " (puArgErr=" + (null==puArgErr?"":puArgErr.getValue()) + ")"); this.pExcepInfo = pExcepInfo; this.puArgErr = puArgErr; } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPoint.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPoint.java new file mode 100644 index 0000000000..fb5132f134 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPoint.java @@ -0,0 +1,56 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; + +public class ConnectionPoint extends Unknown implements IConnectionPoint { + + public ConnectionPoint(Pointer pointer) { + super(pointer); + } + + @Override + public HRESULT GetConnectionInterface(IID iid) { + final int vTableId = 3; + return (HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), iid }, HRESULT.class); + } + + void GetConnectionPointContainer() { + final int vTableId = 4; + + } + + @Override + public HRESULT Advise(IUnknownCallback pUnkSink, DWORDByReference pdwCookie) { + final int vTableId = 5; + + return (HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), pUnkSink.getPointer(), + pdwCookie }, HRESULT.class); + } + + @Override + public HRESULT Unadvise(DWORD dwCookie) { + final int vTableId = 6; + + return (HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), dwCookie }, HRESULT.class); + } + + void EnumConnections() { + final int vTableId = 7; + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPointContainer.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPointContainer.java new file mode 100644 index 0000000000..481905c1fb --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/ConnectionPointContainer.java @@ -0,0 +1,50 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public class ConnectionPointContainer extends Unknown implements + IConnectionPointContainer { + + public ConnectionPointContainer(Pointer pointer) { + super(pointer); + } + + public HRESULT EnumConnectionPoints() { + // I think the magic number here is worked out by counting the number of + // methods in the full interface, as this inherits IUnknown, which + // has 3 methods, we start here at 3 (0 indexed). + final int vTableId = 3; + + +// return (HRESULT) this._invokeNativeObject(3, +// new Object[] { this.getPointer(), riid, ppCP }, HRESULT.class); + throw new UnsupportedOperationException(); + } + + @Override + public HRESULT FindConnectionPoint(REFIID riid, PointerByReference ppCP) { + // I think the magic number here is worked out by counting the number of + // methods in the full interface, + // this as this inherits IUnknown, which has 3 methods, we have here 4. + // second in this class + final int vTableId = 4; + return (HRESULT) this._invokeNativeObject(vTableId, + new Object[] { this.getPointer(), riid, ppCP }, HRESULT.class); + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/Dispatch.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/Dispatch.java index 71fd3d546f..c5f6577c42 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/Dispatch.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/Dispatch.java @@ -16,6 +16,7 @@ import com.sun.jna.Structure; import com.sun.jna.WString; import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.OaIdl.DISPID; import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; @@ -24,6 +25,7 @@ import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; @@ -97,7 +99,7 @@ public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, * the rg disp id * @return the hresult */ - public HRESULT GetIDsOfNames(IID riid, WString[] rgszNames, int cNames, + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, DISPIDByReference rgDispId) { return (HRESULT) this._invokeNativeObject(5, new Object[] { this.getPointer(), riid, rgszNames, cNames, @@ -125,8 +127,8 @@ public HRESULT GetIDsOfNames(IID riid, WString[] rgszNames, int cNames, * the pu arg err * @return the hresult */ - public HRESULT Invoke(DISPID dispIdMember, IID riid, LCID lcid, - DISPID wFlags, DISPPARAMS pDispParams, + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, + WORD wFlags, DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, IntByReference puArgErr) { return (HRESULT) this diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchListener.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchListener.java new file mode 100644 index 0000000000..0043ab114f --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchListener.java @@ -0,0 +1,104 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import java.util.Arrays; +import java.util.List; + +import com.sun.jna.CallbackThreadInitializer; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; + +public class DispatchListener extends Structure { + public DispatchListener(IDispatchCallback callback) { + this.vtbl = this.constructVTable(); + this.initVTable(callback); + super.write(); + } + public DispatchVTable.ByReference vtbl; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "vtbl" }); + } + + protected DispatchVTable.ByReference constructVTable() { + return new DispatchVTable.ByReference(); + } + + protected void initVTable(final IDispatchCallback callback) { + this.vtbl.QueryInterfaceCallback = new DispatchVTable.QueryInterfaceCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject) { + return callback.QueryInterface(refid, ppvObject); + } + }; + this.vtbl.AddRefCallback = new DispatchVTable.AddRefCallback() { + @Override + public int invoke(Pointer thisPointer) { + return callback.AddRef(); + } + }; + this.vtbl.ReleaseCallback = new DispatchVTable.ReleaseCallback() { + @Override + public int invoke(Pointer thisPointer) { + return callback.Release(); + } + }; + this.vtbl.GetTypeInfoCountCallback = new DispatchVTable.GetTypeInfoCountCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, UINTByReference pctinfo) { + return callback.GetTypeInfoCount(pctinfo); + } + }; + this.vtbl.GetTypeInfoCallback = new DispatchVTable.GetTypeInfoCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, UINT iTInfo, LCID lcid, PointerByReference ppTInfo) { + return callback.GetTypeInfo(iTInfo, lcid, ppTInfo); + } + }; + this.vtbl.GetIDsOfNamesCallback = new DispatchVTable.GetIDsOfNamesCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, + DISPIDByReference rgDispId) { + return callback.GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId); + } + }; + this.vtbl.InvokeCallback = new DispatchVTable.InvokeCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags, + DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, + IntByReference puArgErr) { + + return callback.Invoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); + } + }; + + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchVTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchVTable.java new file mode 100644 index 0000000000..16fb47fd51 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchVTable.java @@ -0,0 +1,89 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.COM.UnknownVTable.AddRefCallback; +import com.sun.jna.platform.win32.COM.UnknownVTable.QueryInterfaceCallback; +import com.sun.jna.platform.win32.COM.UnknownVTable.ReleaseCallback; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.win32.DLLCallback; +import com.sun.jna.win32.StdCallLibrary; + +public class DispatchVTable extends Structure { + public static class ByReference extends DispatchVTable implements Structure.ByReference { + } + + public QueryInterfaceCallback QueryInterfaceCallback; + public AddRefCallback AddRefCallback; + public ReleaseCallback ReleaseCallback; + public GetTypeInfoCountCallback GetTypeInfoCountCallback; + public GetTypeInfoCallback GetTypeInfoCallback; + public GetIDsOfNamesCallback GetIDsOfNamesCallback; + public InvokeCallback InvokeCallback; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "QueryInterfaceCallback", "AddRefCallback", "ReleaseCallback","GetTypeInfoCountCallback", "GetTypeInfoCallback", + "GetIDsOfNamesCallback", "InvokeCallback" }); + } + + public static interface QueryInterfaceCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject); + } + + public static interface AddRefCallback extends StdCallLibrary.StdCallCallback { + int invoke(Pointer thisPointer); + } + + public static interface ReleaseCallback extends StdCallLibrary.StdCallCallback { + int invoke(Pointer thisPointer); + } + + public static interface GetTypeInfoCountCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, UINTByReference pctinfo); + } + + public static interface GetTypeInfoCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, UINT iTInfo, LCID lcid, PointerByReference ppTInfo); + } + + public static interface GetIDsOfNamesCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, + DISPIDByReference rgDispId); + } + + public static interface InvokeCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags, + DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, + IntByReference puArgErr); + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/EnumMoniker.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/EnumMoniker.java new file mode 100644 index 0000000000..38127674ea --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/EnumMoniker.java @@ -0,0 +1,71 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinDef.ULONG; +import com.sun.jna.platform.win32.WinDef.ULONGByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public class EnumMoniker extends Unknown implements IEnumMoniker { + + public EnumMoniker(Pointer pointer) { + super(pointer); + } + + // The magic number values for (vTableId) below, are worked out by + // counting the number of methods in the full interface (0 indexed), as this + // inherits IUnknown, which has 3 methods, we start here at 3. + + @Override + public HRESULT Next(ULONG celt, PointerByReference rgelt, ULONGByReference pceltFetched) { + final int vTableId = 3; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), celt, + rgelt, pceltFetched }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT Skip(ULONG celt) { + final int vTableId = 4; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), celt }, + WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT Reset() { + final int vTableId = 5; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), }, + WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT Clone(PointerByReference ppenum) { + final int vTableId = 6; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, + new Object[] { this.getPointer(), ppenum }, WinNT.HRESULT.class); + + return hr; + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPoint.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPoint.java new file mode 100644 index 0000000000..643f741794 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPoint.java @@ -0,0 +1,66 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.platform.win32.WinNT; + +public interface IConnectionPoint extends IUnknown { + final static IID IID_IConnectionPoint = new IID( + "B196B286-BAB4-101A-B69C-00AA00341D07"); + + /** + * + * + * @param iid + * @return + */ + HRESULT GetConnectionInterface(IID iid); + + /** + * + * When Advise is called, the called COM object will callback 'QueryInterface' asking for a number of + * different interfaces, for example: + * - {00000003-0000-0000-C000-000000000046} - IMarshal + * - {00000003-0000-0000-C000-000000000046} + * - {0000001B-0000-0000-C000-000000000046} - IdentityUnmarshal + * - {00000000-0000-0000-C000-000000000046} - IUnknown + * - {00000018-0000-0000-C000-000000000046} - IStdMarshalInfo + * - {00000019-0000-0000-C000-000000000046} - IExternalConnection + * - {4C1E39E1-E3E3-4296-AA86-EC938D896E92} - (some unknown private interface) + * - interface of this ConnectionPoint + * + * + * {@code + * HRESULT Advise( + * [in] IUnknown *pUnkSink, + * [out] DWORD *pdwCookie + * ); + * } + * + * @param pUnkSink + * @param pdwCookie + * @return + */ + WinNT.HRESULT Advise(IUnknownCallback pUnkSink, DWORDByReference pdwCookie); + + /** + * + * @param dwCookie + * @return + */ + HRESULT Unadvise(DWORD dwCookie); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPointContainer.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPointContainer.java new file mode 100644 index 0000000000..e0e354002d --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IConnectionPointContainer.java @@ -0,0 +1,35 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public interface IConnectionPointContainer extends IUnknown { + public final static IID IID_IConnectionPointContainer = new IID("B196B284-BAB4-101A-B69C-00AA00341D07"); + + /** + * @code{ + * HRESULT FindConnectionPoint( + * [in] REFIID riid, + * [out] IConnectionPoint **ppCP + * ); + * } + * @param riid + * @param ppCP + * @return + */ + public HRESULT FindConnectionPoint( REFIID riid, PointerByReference ppCP ); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatch.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatch.java index 8906ab543e..e4904cb983 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatch.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatch.java @@ -14,6 +14,7 @@ import com.sun.jna.WString; import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.OaIdl.DISPID; import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; @@ -22,6 +23,7 @@ import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; @@ -45,11 +47,11 @@ public interface IDispatch extends IUnknown { public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, PointerByReference ppTInfo); - public HRESULT GetIDsOfNames(IID riid, WString[] rgszNames, int cNames, + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, DISPIDByReference rgDispId); - public HRESULT Invoke(DISPID dispIdMember, IID riid, LCID lcid, - DISPID wFlags, DISPPARAMS pDispParams, + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, + WORD wFlags, DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, IntByReference puArgErr); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatchCallback.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatchCallback.java new file mode 100644 index 0000000000..2140cfd295 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatchCallback.java @@ -0,0 +1,18 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + + +public interface IDispatchCallback extends IDispatch, IUnknownCallback { + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IEnumMoniker.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IEnumMoniker.java new file mode 100644 index 0000000000..b3f3618f99 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IEnumMoniker.java @@ -0,0 +1,94 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.WinDef.ULONG; +import com.sun.jna.platform.win32.WinDef.ULONGByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; + +/** + * Enumerates the components of a moniker or the monikers in a table of monikers. + * + * @see MSDN + * + */ +public interface IEnumMoniker extends IUnknown { + + public final static IID IID = new IID("{00000102-0000-0000-C000-000000000046}"); + + /** + * Creates a new enumerator that contains the same enumeration state as the + * current one. + * + * This method makes it possible to record a particular point in the + * enumeration sequence and then return to that point at a later time. The + * caller must release this new enumerator separately from the first + * enumerator. + * + * {@code + * HRESULT Clone( + * [out] IEnumMoniker **ppenum + * ); + * } + * + * @see MSDN + */ + HRESULT Clone(PointerByReference ppenum); + + /** + * Retrieves the specified number of items in the enumeration sequence. + * + * Note: The caller is responsible for calling Release through each pointer + * enumerated. + * + * {@code + * HRESULT Next( + * [in] ULONG celt, + * [out] IMoniker **rgelt, + * [in, out] ULONG *pceltFetched + * ); + * } + * + * @see MSDN + * + */ + HRESULT Next(ULONG celt, PointerByReference rgelt, ULONGByReference pceltFetched); + + /** + * Resets the enumeration sequence to the beginning. + * + * {@code + * HRESULT Reset(); + * } + * + * @see MSDN + * + */ + HRESULT Reset(); + + /** + * Skips over the specified number of items in the enumeration sequence. + * + * {@code + * HRESULT Skip( + * [in] ULONG celt + * ); + * } + * + * @see MSDN + * + */ + HRESULT Skip(ULONG celt); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IMoniker.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IMoniker.java new file mode 100644 index 0000000000..7535089a1d --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IMoniker.java @@ -0,0 +1,94 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.WTypes.BSTRByReference; +import com.sun.jna.platform.win32.WTypes.LPSTR; +import com.sun.jna.platform.win32.WinNT.HRESULT; + + +/** + * Enables you to use a moniker object, which contains information that uniquely + * identifies a COM object. + * + * (Unimplemented, placeholder only at present) + * + * @see MSDN + * + */ +public interface IMoniker extends IPersistStream { + + /** + * Binds to the specified object. The binding process involves finding the + * object, putting it into the running state if necessary, and providing the + * caller with a pointer to a specified interface on the identified object. + * + * {@code + * HRESULT BindToObject( + * [in] IBindCtx *pbc, + * [in] IMoniker *pmkToLeft, + * [in] REFIID riidResult, + * [out] void **ppvResult + * ); + * } + * + * @see MSDN + */ + void BindToObject(); + + void BindToStorage(); + + void Reduce(); + + void ComposeWith(); + + void Enum(); + + void IsEqual(); + + void Hash(); + + void IsRunning(); + + void GetTimeOfLastChange(); + + void Inverse(); + + void CommonPrefixWith(); + + /** + * Retrieves the display name for the moniker. + * + * {@code + * HRESULT GetDisplayName( + * [in] IBindCtx *pbc, + * [in] IMoniker *pmkToLeft, + * [out] LPOLESTR *ppszDisplayName + * ); + * + * @see MSDN + * + * } + */ + HRESULT GetDisplayName(Pointer pbc, Pointer pmkToLeft, BSTRByReference ppszDisplayName); + + void ParseDisplayName(); + + void IsSystemMoniker(); + + void RelativePathTo(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersist.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersist.java new file mode 100644 index 0000000000..8b60559db5 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersist.java @@ -0,0 +1,40 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.platform.win32.Guid.CLSID; + +/** + * Provides the CLSID of an object that can be stored persistently in the + * system. Allows the object to specify which object handler to use in the + * client process, as it is used in the default implementation of marshaling. + * + * @see MSDN + * + */ +public interface IPersist extends IUnknown { + + /** + * Retrieves the class identifier (CLSID) of the object. + * + * {@code + * HRESULT GetClassID( + * [out] CLSID *pClassID + * ); + * } + * + * MSDN + */ + CLSID GetClassID(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersistStream.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersistStream.java new file mode 100644 index 0000000000..5604e373f5 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IPersistStream.java @@ -0,0 +1,57 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + + +/** + * Enables the saving and loading of objects that use a simple serial stream for their storage needs. + * + * @see MSDN + * + */ +public interface IPersistStream extends IPersist { + + /** + * Determines whether an object has changed since it was last saved to its + * stream. + * + * (Unimplemented) + * + */ + boolean IsDirty(); + + /** + * Initializes an object from the stream where it was saved previously + * + * (Unimplemented) + * + */ + + void Load(IStream stm); + + /** + * Saves an object to the specified stream. + * + * (Unimplemented) + * + */ + void Save(IStream stm); + + /** + * Retrieves the size of the stream needed to save the object. + * + * (Unimplemented) + * + */ + void GetSizeMax(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IRunningObjectTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IRunningObjectTable.java new file mode 100644 index 0000000000..9a5709a3e5 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IRunningObjectTable.java @@ -0,0 +1,152 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.WinBase.FILETIME; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +/** + * Manages access to the running object table (ROT), a globally accessible + * look-up table on each workstation. + * + * @see MSDN + * + */ +public interface IRunningObjectTable extends IUnknown { + + public final static IID IID = new IID("{00000010-0000-0000-C000-000000000046}"); + + /** + * Creates and returns a pointer to an enumerator that can list the monikers + * of all the objects currently registered in the running object table + * (ROT). + * + * {@code + * HRESULT EnumRunning( + * [out] IEnumMoniker **ppenumMoniker + * ); + * } + * + * @see MSDN + * + */ + HRESULT EnumRunning(PointerByReference ppenumMoniker); + + /** + * + * Determines whether the object identified by the specified moniker is + * running, and if it is, retrieves a pointer to that object. + * + * {@code + * HRESULT GetObject( + * [in] IMoniker *pmkObjectName, + * [out] IUnknown **ppunkObject + * ); + * } + * + * @see MSDN + * + */ + HRESULT GetObject(Pointer pmkObjectName, PointerByReference ppunkObject); + + /** + * Retrieves the time that an object was last modified. + * + * {@code + * HRESULT GetTimeOfLastChange( + * [in] IMoniker *pmkObjectName, + * [out] FILETIME *pfiletime + * ); + * } + * + * @see MSDN + * + */ + HRESULT GetTimeOfLastChange(Pointer pmkObjectName, FILETIME.ByReference pfiletime); + + /** + * Determines whether the object identified by the specified moniker is + * currently running. + * + * {@code + * HRESULT IsRunning( + * [in] IMoniker *pmkObjectName + * ); + * } + * + * @see MSDN + * + */ + HRESULT IsRunning(Pointer pmkObjectName); + + /** + * Records the time that a running object was last modified. + * + * {@code + * HRESULT NoteChangeTime( + * [in] DWORD dwRegister, + * [in] FILETIME *pfiletime + * ); + * } + * + * @see MSDN + * + */ + HRESULT NoteChangeTime(DWORD dwRegister, FILETIME pfiletime); + + /** + * Registers an object and its identifying moniker in the running object + * table (ROT). + * + * {@code + * HRESULT Register( + * [in] DWORD grfFlags, + * [in] IUnknown *punkObject, + * [in] IMoniker *pmkObjectName, + * [out] DWORD *pdwRegister + * ); + * } + * + * @see MSDN + * + */ + HRESULT Register(DWORD grfFlags, Pointer punkObject, Pointer pmkObjectName, DWORDByReference pdwRegister); + + /** + * Removes an entry from the running object table (ROT) that was previously + * registered by a call to IRunningObjectTable.Register. + * + * {@code + * HRESULT Revoke( + * [in] DWORD dwRegister + * ); + * } + * + * @see MSDN + * + */ + HRESULT Revoke(DWORD dwRegister); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IStream.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IStream.java new file mode 100644 index 0000000000..a7fa02570d --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IStream.java @@ -0,0 +1,29 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +/** + * The IStream interface lets you read and write data to stream objects. Stream + * objects contain the data in a structured storage object, where storages + * provide the structure. Simple data can be written directly to a stream but, + * most frequently, streams are elements nested within a storage object. They + * are similar to standard files. + * + * (Place holder, incomplete) + * + * @see MSDN + * + */ +public interface IStream { + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknown.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknown.java index 073cbe0e60..061f6114e8 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknown.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknown.java @@ -13,6 +13,7 @@ package com.sun.jna.platform.win32.COM; import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.PointerByReference; @@ -31,7 +32,7 @@ public interface IUnknown { public final static IID IID_IUNKNOWN = new IID( "{00000000-0000-0000-C000-000000000046}"); - public HRESULT QueryInterface(IID riid, PointerByReference ppvObject); + public HRESULT QueryInterface(REFIID.ByValue riid, PointerByReference ppvObject); public int AddRef(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknownCallback.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknownCallback.java new file mode 100644 index 0000000000..d1ae76c95f --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknownCallback.java @@ -0,0 +1,19 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; + +public interface IUnknownCallback extends IUnknown { + Pointer getPointer(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/Moniker.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/Moniker.java new file mode 100644 index 0000000000..db695646d5 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/Moniker.java @@ -0,0 +1,173 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.WTypes.BSTRByReference; +import com.sun.jna.platform.win32.WTypes.LPSTR; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.WinNT.HRESULT; + +public class Moniker extends Unknown implements IMoniker { + + public static class ByReference extends Moniker implements Structure.ByReference { + } + + public Moniker() { + } + + public Moniker(Pointer pointer) { + super(pointer); + } + + // There are 8 virtual methods in the ancestors of this class/interfaces + static final int vTableIdStart = 7; + + @Override + public void BindToObject() { + final int vTableId = vTableIdStart + 1; + + throw new UnsupportedOperationException(); + } + + @Override + public void BindToStorage() { + final int vTableId = vTableIdStart + 2; + + throw new UnsupportedOperationException(); + } + + @Override + public void Reduce() { + final int vTableId = vTableIdStart + 3; + + throw new UnsupportedOperationException(); + } + + @Override + public void ComposeWith() { + final int vTableId = vTableIdStart + 4; + + throw new UnsupportedOperationException(); + } + + @Override + public void Enum() { + final int vTableId = vTableIdStart + 5; + + throw new UnsupportedOperationException(); + } + + @Override + public void IsEqual() { + final int vTableId = vTableIdStart + 6; + + throw new UnsupportedOperationException(); + } + + @Override + public void Hash() { + final int vTableId = vTableIdStart + 7; + + throw new UnsupportedOperationException(); + } + + @Override + public void IsRunning() { + final int vTableId = vTableIdStart + 8; + + throw new UnsupportedOperationException(); + } + + @Override + public void GetTimeOfLastChange() { + final int vTableId = vTableIdStart + 9; + + throw new UnsupportedOperationException(); + } + + @Override + public void Inverse() { + final int vTableId = vTableIdStart + 10; + + throw new UnsupportedOperationException(); + } + + @Override + public void CommonPrefixWith() { + final int vTableId = vTableIdStart + 11; + + throw new UnsupportedOperationException(); + } + + @Override + public void RelativePathTo() { + final int vTableId = vTableIdStart + 12; + + throw new UnsupportedOperationException(); + } + + @Override + public HRESULT GetDisplayName(Pointer pbc, Pointer pmkToLeft, BSTRByReference ppszDisplayName) { + final int vTableId = vTableIdStart + 13; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), pbc, + pmkToLeft, ppszDisplayName }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public void ParseDisplayName() { + final int vTableId = vTableIdStart + 14; + + throw new UnsupportedOperationException(); + } + + @Override + public void IsSystemMoniker() { + final int vTableId = vTableIdStart + 15; + + throw new UnsupportedOperationException(); + } + + // ------------------------ IPersistStream ---------------------------- + @Override + public boolean IsDirty() { + throw new UnsupportedOperationException(); + } + + @Override + public void Load(IStream stm) { + throw new UnsupportedOperationException(); + } + + @Override + public void Save(IStream stm) { + throw new UnsupportedOperationException(); + } + + @Override + public void GetSizeMax() { + throw new UnsupportedOperationException(); + } + + @Override + public CLSID GetClassID() { + throw new UnsupportedOperationException(); + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/RunningObjectTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/RunningObjectTable.java new file mode 100644 index 0000000000..e635c500d8 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/RunningObjectTable.java @@ -0,0 +1,110 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.platform.win32.WinBase.FILETIME; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public class RunningObjectTable extends Unknown implements IRunningObjectTable { + + public static class ByReference extends RunningObjectTable implements Structure.ByReference { + } + + public RunningObjectTable() { + } + + public RunningObjectTable(Pointer pointer) { + super(pointer); + } + + // The magic number values for (vTableId) below, are worked out by + // counting the number of methods in the full interface (0 indexed), as this + // inherits IUnknown, which has 3 methods, we start here at 3. + + @Override + public HRESULT Register(DWORD grfFlags, Pointer punkObject, Pointer pmkObjectName, DWORDByReference pdwRegister) { + final int vTableId = 3; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + grfFlags, punkObject, pmkObjectName, pdwRegister }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT Revoke(DWORD dwRegister) { + final int vTableId = 4; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + dwRegister }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT IsRunning(Pointer pmkObjectName) { + final int vTableId = 5; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + pmkObjectName }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT GetObject(Pointer pmkObjectName, PointerByReference ppunkObject) { + final int vTableId = 6; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + pmkObjectName, ppunkObject }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT NoteChangeTime(DWORD dwRegister, FILETIME pfiletime) { + final int vTableId = 7; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + dwRegister, pfiletime }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT GetTimeOfLastChange(Pointer pmkObjectName, FILETIME.ByReference pfiletime) { + final int vTableId = 8; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + pmkObjectName, pfiletime }, WinNT.HRESULT.class); + + return hr; + } + + @Override + public HRESULT EnumRunning(PointerByReference ppenumMoniker) { + final int vTableId = 9; + + WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), + ppenumMoniker }, WinNT.HRESULT.class); + + return hr; + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/Unknown.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/Unknown.java index 366be7d050..a3d993bff4 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/Unknown.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/Unknown.java @@ -15,6 +15,7 @@ import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.PointerByReference; @@ -55,7 +56,7 @@ public Unknown(Pointer pvInstance) { * the ppv object * @return the hresult */ - public HRESULT QueryInterface(IID riid, PointerByReference ppvObject) { + public HRESULT QueryInterface(REFIID.ByValue riid, PointerByReference ppvObject) { return (HRESULT) this._invokeNativeObject(0, new Object[] { this.getPointer(), riid, ppvObject }, HRESULT.class); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownListener.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownListener.java new file mode 100644 index 0000000000..8c9322b1bb --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownListener.java @@ -0,0 +1,66 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import java.util.Arrays; +import java.util.List; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.platform.win32.Guid; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public class UnknownListener extends Structure { + + public UnknownListener(IUnknownCallback callback) { + this.vtbl = this.constructVTable(); + this.initVTable(callback); + super.write(); + } + + public UnknownVTable.ByReference vtbl; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "vtbl" }); + } + + protected UnknownVTable.ByReference constructVTable() { + return new UnknownVTable.ByReference(); + } + + protected void initVTable(final IUnknownCallback callback) { + this.vtbl.QueryInterfaceCallback = new UnknownVTable.QueryInterfaceCallback() { + @Override + public HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject) { + return callback.QueryInterface(refid, ppvObject); + } + }; + this.vtbl.AddRefCallback = new UnknownVTable.AddRefCallback() { + @Override + public int invoke(Pointer thisPointer) { + return callback.AddRef(); + } + }; + this.vtbl.ReleaseCallback = new UnknownVTable.ReleaseCallback() { + @Override + public int invoke(Pointer thisPointer) { + return callback.Release(); + } + }; + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownVTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownVTable.java new file mode 100644 index 0000000000..ec53e1be8b --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/UnknownVTable.java @@ -0,0 +1,49 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import java.util.Arrays; +import java.util.List; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.win32.StdCallLibrary; + +public class UnknownVTable extends Structure { + public static class ByReference extends UnknownVTable implements Structure.ByReference { + } + + public QueryInterfaceCallback QueryInterfaceCallback; + public AddRefCallback AddRefCallback; + public ReleaseCallback ReleaseCallback; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "QueryInterfaceCallback", "AddRefCallback", "ReleaseCallback" }); + } + + public static interface QueryInterfaceCallback extends StdCallLibrary.StdCallCallback { + WinNT.HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject); + } + + public static interface AddRefCallback extends StdCallLibrary.StdCallCallback { + int invoke(Pointer thisPointer); + } + + public static interface ReleaseCallback extends StdCallLibrary.StdCallCallback { + int invoke(Pointer thisPointer); + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/AbstractComEventCallbackListener.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/AbstractComEventCallbackListener.java new file mode 100644 index 0000000000..0204d83da4 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/AbstractComEventCallbackListener.java @@ -0,0 +1,29 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.IDispatchCallback; + +public abstract class AbstractComEventCallbackListener implements IComEventCallbackListener { + + public AbstractComEventCallbackListener() { + this.dispatchCallback = null; + } + + IDispatchCallback dispatchCallback; + public void setDispatchCallbackListener(IDispatchCallback dispatchCallback) { + this.dispatchCallback = dispatchCallback; + } + + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/CallbackProxy.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/CallbackProxy.java new file mode 100644 index 0000000000..7a8ccc31ee --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/CallbackProxy.java @@ -0,0 +1,273 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.lang.Thread.UncaughtExceptionHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import com.sun.jna.Pointer; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.Guid; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.Variant; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.Variant.VariantArg; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.Dispatch; +import com.sun.jna.platform.win32.COM.DispatchListener; +import com.sun.jna.platform.win32.COM.IDispatch; +import com.sun.jna.platform.win32.COM.IDispatchCallback; +import com.sun.jna.platform.win32.COM.Unknown; +import com.sun.jna.platform.win32.COM.util.annotation.ComEventCallback; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; + +public class CallbackProxy implements IDispatchCallback { + + public CallbackProxy(Factory factory, Class comEventCallbackInterface, + IComEventCallbackListener comEventCallbackListener) { + this.factory = factory; + this.comEventCallbackInterface = comEventCallbackInterface; + this.comEventCallbackListener = comEventCallbackListener; + this.listenedToRiid = this.createRIID(comEventCallbackInterface); + this.dsipIdMap = this.createDispIdMap(comEventCallbackInterface); + this.dispatchListener = new DispatchListener(this); + this.executorService = Executors.newSingleThreadExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread thread = new Thread(r, "COM Event Callback executor"); + thread.setDaemon(true); + thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + CallbackProxy.this.factory.comThread.uncaughtExceptionHandler.uncaughtException(t, e); + } + }); + return thread; + } + }); + } + + Factory factory; + Class comEventCallbackInterface; + IComEventCallbackListener comEventCallbackListener; + REFIID.ByValue listenedToRiid; + public DispatchListener dispatchListener; + Map dsipIdMap; + ExecutorService executorService; + + REFIID.ByValue createRIID(Class comEventCallbackInterface) { + ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class); + if (null == comInterfaceAnnotation) { + throw new COMException( + "advise: Interface must define a value for either iid via the ComInterface annotation"); + } + String iidStr = comInterfaceAnnotation.iid(); + if (null == iidStr || iidStr.isEmpty()) { + throw new COMException("ComInterface must define a value for iid"); + } + return new REFIID.ByValue(new IID(iidStr).getPointer()); + } + + Map createDispIdMap(Class comEventCallbackInterface) { + Map map = new HashMap(); + + for (Method meth : comEventCallbackInterface.getMethods()) { + ComEventCallback annotation = meth.getAnnotation(ComEventCallback.class); + if (null != annotation) { + int dispId = annotation.dispid(); + if (-1 == dispId) { + dispId = this.fetchDispIdFromName(annotation); + } + map.put(new DISPID(dispId), meth); + } + } + + return map; + } + + int fetchDispIdFromName(ComEventCallback annotation) { + // TODO + return -1; + } + + void invokeOnThread(final DISPID dispIdMember, final REFIID.ByValue riid, LCID lcid, WORD wFlags, + final DISPPARAMS.ByReference pDispParams) { + // decode arguments + // must decode them on this thread, and create a proxy for any COM objects (IDispatch) + // this will AddRef on the COM object so that it is not cleaned up before we can use it + // on the thread that does the java callback. + List rjargs = new ArrayList(); + if (pDispParams.cArgs.intValue() > 0) { + VariantArg vargs = pDispParams.rgvarg; + vargs.setArraySize(pDispParams.cArgs.intValue()); + for (Variant.VARIANT varg : vargs.variantArg) { + Object jarg = Convert.toJavaObject(varg); + if (jarg instanceof IDispatch) { + IDispatch dispatch = (IDispatch) jarg; + //get raw IUnknown interface + PointerByReference ppvObject = new PointerByReference(); + IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN; + dispatch.QueryInterface(new REFIID.ByValue(iid), ppvObject); + Unknown rawUnk = new Unknown(ppvObject.getValue()); + long unknownId = Pointer.nativeValue( rawUnk.getPointer() ); + int n = rawUnk.Release(); + //Note: unlike in other places, there is currently no COM ref already added for this pointer + IUnknown unk = CallbackProxy.this.factory.createProxy(IUnknown.class, unknownId, dispatch); + rjargs.add(unk); + } else { + rjargs.add(jarg); + } + } + } + final List jargs = new ArrayList(rjargs); + Runnable invokation = new Runnable() { + @Override + public void run() { + try { + if (CallbackProxy.this.dsipIdMap.containsKey(dispIdMember)) { + Method eventMethod = CallbackProxy.this.dsipIdMap.get(dispIdMember); + if (eventMethod.getParameterTypes().length != jargs.size()) { + CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent( + "Trying to invoke method " + eventMethod + " with " + jargs.size() + " arguments", + null); + } else { + try { + // need to convert arguments maybe + List margs = new ArrayList(); + Class[] params = eventMethod.getParameterTypes(); + for (int i = 0; i < eventMethod.getParameterTypes().length; ++i) { + Class paramType = params[i]; + Object jobj = jargs.get(i); + if (jobj != null && paramType.getAnnotation(ComInterface.class) != null) { + if (jobj instanceof IUnknown) { + IUnknown unk = (IUnknown) jobj; + Object mobj = unk.queryInterface(paramType); + margs.add(mobj); + } else { + throw new RuntimeException("Cannot convert argument " + jobj.getClass() + + " to ComInterface " + paramType); + } + } else { + margs.add(jobj); + } + } + eventMethod.invoke(comEventCallbackListener, margs.toArray()); + } catch (Exception e) { + CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent( + "Exception invoking method " + eventMethod, e); + } + } + } else { + CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent( + "No method found with dispId = " + dispIdMember, null); + } + } catch (Exception e) { + CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent( + "Exception receiving callback event ", e); + } + } + }; + this.executorService.execute(invokation); + } + + @Override + public Pointer getPointer() { + return this.dispatchListener.getPointer(); + } + + // ------------------------ IDispatch ------------------------------ + @Override + public HRESULT GetTypeInfoCount(UINTByReference pctinfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, PointerByReference ppTInfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, + DISPIDByReference rgDispId) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags, + DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, + IntByReference puArgErr) { + + this.invokeOnThread(dispIdMember, riid, lcid, wFlags, pDispParams); + + return WinError.S_OK; + } + + // ------------------------ IUnknown ------------------------------ + @Override + public HRESULT QueryInterface(REFIID.ByValue refid, PointerByReference ppvObject) { + if (null == ppvObject) { + return new HRESULT(WinError.E_POINTER); + } + + if (refid.equals(this.listenedToRiid)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Unknown.IID_IUNKNOWN)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Dispatch.IID_IDISPATCH)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + return new HRESULT(WinError.E_NOINTERFACE); + } + + public int AddRef() { + return 0; + } + + public int Release() { + return 0; + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComEventCallbackCookie.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComEventCallbackCookie.java new file mode 100644 index 0000000000..7436f49e32 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComEventCallbackCookie.java @@ -0,0 +1,28 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.WinDef.DWORD; + +public class ComEventCallbackCookie implements IComEventCallbackCookie { + + public ComEventCallbackCookie(DWORD value) { + this.value = value; + } + + DWORD value; + public DWORD getValue() { + return this.value; + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java new file mode 100644 index 0000000000..3ac5c13407 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java @@ -0,0 +1,129 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.lang.Thread.UncaughtExceptionHandler; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.COM.COMUtils; + +public class ComThread { + + ExecutorService executor; + Runnable firstTask; + boolean requiresInitialisation; + long timeoutMilliseconds; + UncaughtExceptionHandler uncaughtExceptionHandler; + + public ComThread(final String threadName, long timeoutMilliseconds, UncaughtExceptionHandler uncaughtExceptionHandler) { + this(threadName, timeoutMilliseconds, uncaughtExceptionHandler, Ole32.COINIT_MULTITHREADED); + } + + public ComThread(final String threadName, long timeoutMilliseconds, UncaughtExceptionHandler uncaughtExceptionHandler, final int coinitialiseExFlag) { + this.requiresInitialisation = true; + this.timeoutMilliseconds = timeoutMilliseconds; + this.uncaughtExceptionHandler = uncaughtExceptionHandler; + this.firstTask = new Runnable() { + @Override + public void run() { + try { + //If we do not use COINIT_MULTITHREADED, it is necessary to have + // a message loop see - + // [http://www.codeguru.com/cpp/com-tech/activex/apts/article.php/c5529/Understanding-COM-Apartments-Part-I.htm] + // [http://www.codeguru.com/cpp/com-tech/activex/apts/article.php/c5533/Understanding-COM-Apartments-Part-II.htm] + WinNT.HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, coinitialiseExFlag); + COMUtils.checkRC(hr); + ComThread.this.requiresInitialisation = false; + } catch (Throwable t) { + ComThread.this.uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), t); + } + } + }; + executor = Executors.newSingleThreadExecutor(new ThreadFactory() { + + @Override + public Thread newThread(Runnable r) { + if (!ComThread.this.requiresInitialisation) { + // something has gone wrong! + throw new RuntimeException("ComThread executor has a problem."); + } + Thread thread = new Thread(r, threadName); + //make sure this is a daemon thread, or it will stop JVM existing + // if program does not call terminate(); + thread.setDaemon(true); + + thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + ComThread.this.requiresInitialisation = true; + ComThread.this.uncaughtExceptionHandler.uncaughtException(t, e); + } + }); + + return thread; + } + }); + + } + + /** + * Stop the COM Thread. + * + * @param timeoutMilliseconds + * number of milliseconds to wait for a clean shutdown before a + * forced shutdown is attempted + */ + public void terminate(long timeoutMilliseconds) { + try { + + executor.submit(new Runnable() { + @Override + public void run() { + Ole32.INSTANCE.CoUninitialize(); + } + }).get(timeoutMilliseconds, TimeUnit.MILLISECONDS); + + executor.shutdown(); + + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } catch (TimeoutException e) { + executor.shutdownNow(); + } + } + + @Override + protected void finalize() throws Throwable { + if (!executor.isShutdown()) { + this.terminate(100); + } + } + + public T execute(Callable task) throws TimeoutException, InterruptedException, ExecutionException { + if (this.requiresInitialisation) { + executor.execute(firstTask); + } + return executor.submit(task).get(this.timeoutMilliseconds, TimeUnit.MILLISECONDS); + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Convert.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Convert.java new file mode 100644 index 0000000000..4b0f03a55c --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Convert.java @@ -0,0 +1,92 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Date; + +import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.Variant.VARIANT; + +public class Convert { + + public static VARIANT toVariant(Object value) { + if (value instanceof Boolean) { + return new VARIANT((Boolean) value); + } else if (value instanceof Long) { + return new VARIANT(new WinDef.LONG((Long) value)); + } else if (value instanceof Integer) { + return new VARIANT((Integer) value); + } else if (value instanceof Short) { + return new VARIANT(new WinDef.SHORT((Short) value)); + } else if (value instanceof Float) { + return new VARIANT((Float) value); + } else if (value instanceof Double) { + return new VARIANT((Double) value); + } else if (value instanceof String) { + return new VARIANT((String) value); + } else if (value instanceof Date) { + return new VARIANT((Date) value); + } else if (value instanceof Proxy) { + InvocationHandler ih = Proxy.getInvocationHandler(value); + ProxyObject pobj = (ProxyObject) ih; + return new VARIANT(pobj.getRawDispatch()); + } + if (value instanceof IComEnum) { + IComEnum enm = (IComEnum) value; + return new VARIANT(new WinDef.LONG(enm.getValue())); + } else { + return null; + } + } + + public static Object toJavaObject(VARIANT value) { + if (null==value) return null; + Object vobj = value.getValue(); + if (vobj instanceof WinDef.BOOL) { + return ((WinDef.BOOL) vobj).booleanValue(); + } else if (vobj instanceof WinDef.LONG) { + return ((WinDef.LONG) vobj).longValue(); + } else if (vobj instanceof WinDef.SHORT) { + return ((WinDef.SHORT) vobj).shortValue(); + } else if (vobj instanceof WinDef.UINT) { + return ((WinDef.UINT) vobj).intValue(); + } else if (vobj instanceof WinDef.WORD) { + return ((WinDef.WORD) vobj).intValue(); + } else if (vobj instanceof WTypes.BSTR) { + return ((WTypes.BSTR) vobj).getValue(); + } + return vobj; + } + + public static T toComEnum(Class enumType, Object value) { + try { + Method m = enumType.getMethod("values"); + T[] values = (T[])m.invoke(null); + for(T t: values) { + if (value.equals(t.getValue())) { + return t; + } + } + } catch (NoSuchMethodException e) { + } catch (IllegalAccessException e) { + } catch (IllegalArgumentException e) { + } catch (InvocationTargetException e) { + } + return null; + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/EnumMoniker.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/EnumMoniker.java new file mode 100644 index 0000000000..f12bf8d2d1 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/EnumMoniker.java @@ -0,0 +1,166 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.util.Iterator; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.platform.win32.COM.Dispatch; +import com.sun.jna.platform.win32.COM.IEnumMoniker; +import com.sun.jna.platform.win32.COM.Moniker; +import com.sun.jna.ptr.PointerByReference; + +/** + * Enumerates the components of a moniker or the monikers in a table of + * monikers. + * + * @see MSDN + * + */ +public class EnumMoniker implements Iterable { + + protected EnumMoniker(IEnumMoniker raw, com.sun.jna.platform.win32.COM.IRunningObjectTable rawRot, + Factory factory) { + this.rawRot = rawRot; + this.raw = raw; + this.factory = factory; + this.comThread = factory.getComThread(); + + try { + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return EnumMoniker.this.raw.Reset(); + } + }); + COMUtils.checkRC(hr); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + + this.cacheNext(); + } + + ComThread comThread; + Factory factory; + com.sun.jna.platform.win32.COM.IRunningObjectTable rawRot; + IEnumMoniker raw; + Moniker rawNext; + + protected void cacheNext() { + try { + final PointerByReference rgelt = new PointerByReference(); + final WinDef.ULONGByReference pceltFetched = new WinDef.ULONGByReference(); + + WinNT.HRESULT hr = EnumMoniker.this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return EnumMoniker.this.raw.Next(new WinDef.ULONG(1), rgelt, pceltFetched); + } + }); + + if (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) { + this.rawNext = new Moniker(rgelt.getValue()); + } else { + if (!WinNT.S_FALSE.equals(hr)) { + COMUtils.checkRC(hr); + } + this.rawNext = null; + } + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + @Override + public Iterator iterator() { + return new Iterator() { + + @Override + public boolean hasNext() { + return null != EnumMoniker.this.rawNext; + } + + @Override + public IDispatch next() { + try { + + final Moniker moniker = EnumMoniker.this.rawNext; + final PointerByReference ppunkObject = new PointerByReference(); + WinNT.HRESULT hr = EnumMoniker.this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return EnumMoniker.this.rawRot.GetObject(moniker.getPointer(), ppunkObject); + } + }); + COMUtils.checkRC(hr); + + // To assist debug, can use the following code + // PointerByReference ppbc = new + // PointerByReference(); + // Ole32.INSTANCE.CreateBindCtx(new DWORD(), ppbc); + // + // BSTRByReference ppszDisplayName = new + // BSTRByReference(); + // hr = moniker.GetDisplayName(ppbc.getValue(), + // moniker.getPointer(), ppszDisplayName); + // COMUtils.checkRC(hr); + // String name = ppszDisplayName.getString(); + // Ole32.INSTANCE.CoTaskMemFree(ppszDisplayName.getPointer().getPointer(0)); + + // TODO: Can we assume that the object is an + // IDispatch ? + // Unknown unk = new + // Unknown(ppunkObject.getValue()); + + Dispatch dispatch = new Dispatch(ppunkObject.getValue()); + EnumMoniker.this.cacheNext(); + IDispatch d = EnumMoniker.this.factory.createProxy(IDispatch.class, dispatch); + //must release a COM Ref, GetObject returns a pointer with +1 + int n = dispatch.Release(); + return d; + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + + } + + @Override + public void remove() { + throw new UnsupportedOperationException("remove"); + } + + }; + } + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java new file mode 100644 index 0000000000..e14a88624b --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java @@ -0,0 +1,278 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.lang.reflect.Proxy; +import java.util.HashSet; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.GUID; +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.OleAuto; +import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.platform.win32.COM.Dispatch; +import com.sun.jna.platform.win32.COM.IDispatch; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; +import com.sun.jna.ptr.PointerByReference; + +public class Factory { + + /** + * Creates a utility COM Factory and a ComThread on which all COM calls are executed. + * NOTE: Remember to call factory.getComThread().terminate() at some appropriate point. + * + */ + public Factory() { + this(new ComThread("Default Factory COM Thread", 5000, new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + //ignore + } + })); + } + + public Factory(ComThread comThread) { + this.comThread = comThread; + this.registeredObjects = new WeakHashMap(); + } + + @Override + protected void finalize() throws Throwable { + try { + this.disposeAll(); + } finally { + super.finalize(); + } + } + + ComThread comThread; + public ComThread getComThread() { + return this.comThread; + } + + /** + * CoInitialize must be called be fore this method. Either explicitly or + * implicitly via other methods. + * + * @return + */ + public IRunningObjectTable getRunningObjectTable() { + try { + + final PointerByReference rotPtr = new PointerByReference(); + + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return Ole32.INSTANCE.GetRunningObjectTable(new WinDef.DWORD(0), rotPtr); + } + }); + COMUtils.checkRC(hr); + com.sun.jna.platform.win32.COM.RunningObjectTable raw = new com.sun.jna.platform.win32.COM.RunningObjectTable( + rotPtr.getValue()); + IRunningObjectTable rot = new RunningObjectTable(raw, this); + return rot; + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + /** + * Creates a ProxyObject for the given interface and IDispatch pointer. + * + */ + public T createProxy(Class comInterface, IDispatch dispatch) { + ProxyObject jop = new ProxyObject(comInterface, dispatch, this); + Object proxy = Proxy.newProxyInstance(comInterface.getClassLoader(), new Class[] { comInterface }, jop); + T result = comInterface.cast(proxy); + return result; + } + + /** only for use when creating ProxyObjects from Callbacks + * + * @param comInterface + * @param unk + * @param dispatch + * @return + */ + T createProxy(Class comInterface, long unknownId, IDispatch dispatch) { + ProxyObject jop = new ProxyObject(comInterface, unknownId, dispatch, this); + Object proxy = Proxy.newProxyInstance(comInterface.getClassLoader(), new Class[] { comInterface }, jop); + T result = comInterface.cast(proxy); + return result; + } + + /** + * Creates a new COM object (CoCreateInstance) for the given progId and + * returns a ProxyObject for the given interface. + */ + public T createObject(Class comInterface) { + try { + + ComObject comObectAnnotation = comInterface.getAnnotation(ComObject.class); + if (null == comObectAnnotation) { + throw new COMException( + "createObject: Interface must define a value for either clsId or progId via the ComInterface annotation"); + } + final GUID guid = this.discoverClsId(comObectAnnotation); + + final PointerByReference ptrDisp = new PointerByReference(); + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return Ole32.INSTANCE.CoCreateInstance(guid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, + ptrDisp); + } + }); + COMUtils.checkRC(hr); + Dispatch d = new Dispatch(ptrDisp.getValue()); + T t = this.createProxy(comInterface,d); + //CoCreateInstance returns a pointer to COM object with a +1 reference count, so we must drop one + //Note: the createProxy adds one + int n = d.Release(); + return t; + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + /** + * Gets and existing COM object (GetActiveObject) for the given progId and + * returns a ProxyObject for the given interface. + */ + public T fetchObject(Class comInterface) { + try { + ComObject comObectAnnotation = comInterface.getAnnotation(ComObject.class); + if (null == comObectAnnotation) { + throw new COMException( + "createObject: Interface must define a value for either clsId or progId via the ComInterface annotation"); + } + final GUID guid = this.discoverClsId(comObectAnnotation); + + final PointerByReference ptrDisp = new PointerByReference(); + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return OleAuto.INSTANCE.GetActiveObject(guid, null, ptrDisp); + } + }); + COMUtils.checkRC(hr); + Dispatch d = new Dispatch(ptrDisp.getValue()); + T t = this.createProxy(comInterface, d); + //GetActiveObject returns a pointer to COM object with a +1 reference count, so we must drop one + //Note: the createProxy adds one + d.Release(); + + return t; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + GUID discoverClsId(ComObject annotation) { + try { + String clsIdStr = annotation.clsId(); + final String progIdStr = annotation.progId(); + if (null != clsIdStr && !clsIdStr.isEmpty()) { + return new CLSID(clsIdStr); + } else if (null != progIdStr && !progIdStr.isEmpty()) { + final CLSID.ByReference rclsid = new CLSID.ByReference(); + + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return Ole32.INSTANCE.CLSIDFromProgID(progIdStr, rclsid); + } + }); + + COMUtils.checkRC(hr); + return rclsid; + } else { + throw new COMException("ComObject must define a value for either clsId or progId"); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + //factory needs to keep a register of all handles to COM objects so that it can clean them up properly + // (if java had an out of scope clean up destructor like C++, this wouldn't be needed) + WeakHashMap registeredObjects; + public void register(ProxyObject proxyObject) { + synchronized (this.registeredObjects) { + //ProxyObject identity resolves to the underlying native pointer value + // different java ProxyObjects will resolve to the same pointer + // thus we need to count the number of references. + if (this.registeredObjects.containsKey(proxyObject)) { + int r = this.registeredObjects.get(proxyObject); + this.registeredObjects.put(proxyObject, r+1); + } else { + this.registeredObjects.put(proxyObject, 1); + } + } + } + + public void unregister(ProxyObject proxyObject, int d) { + synchronized (this.registeredObjects) { + if (this.registeredObjects.containsKey(proxyObject)) { + int r = this.registeredObjects.get(proxyObject); + if (r > 1) { + this.registeredObjects.put(proxyObject, r-d); + } else { + this.registeredObjects.remove(proxyObject); + } + } else { + throw new RuntimeException("Tried to dispose a ProxyObject that is not registered"); + } + + } + } + + public void disposeAll() { + synchronized (this.registeredObjects) { + Set s = new HashSet(this.registeredObjects.keySet()); + for(ProxyObject proxyObject : s) { + int r = this.registeredObjects.get(proxyObject); + proxyObject.dispose(r); + } + this.registeredObjects.clear(); + } + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEnum.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEnum.java new file mode 100644 index 0000000000..4e50344208 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEnum.java @@ -0,0 +1,17 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +public interface IComEnum { + long getValue(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackCookie.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackCookie.java new file mode 100644 index 0000000000..9897e617cf --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackCookie.java @@ -0,0 +1,17 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +public interface IComEventCallbackCookie { + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackListener.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackListener.java new file mode 100644 index 0000000000..6ad2ae184a --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IComEventCallbackListener.java @@ -0,0 +1,23 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.IDispatchCallback; + +public interface IComEventCallbackListener { + + void setDispatchCallbackListener(IDispatchCallback dispatchCallback); + + void errorReceivingCallbackEvent(String message, Exception exception); + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPoint.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPoint.java new file mode 100644 index 0000000000..9311e53394 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPoint.java @@ -0,0 +1,39 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.COMException; + +public interface IConnectionPoint { + + /** + * Set up the comEventCallbackListener to receive callback events from the target COM object + * + * @param comEventCallbackInterface - the COM interface that the listener will receive events from + * @param comEventCallback - and object that will receive the callback events + * @return - a cookie that can be used to detach (unadvise) the event callback listener + * + * throws COMException if an error occurs trying to set up the listener on the target COM object, + * see exception cause for details. + * + */ + IComEventCallbackCookie advise(Class comEventCallbackInterface, IComEventCallbackListener comEventCallbackListener) throws COMException; + + /** + * Stop listening for callback events + * + * @param comEventCallbackInterface - the interface that is being listened to + * @param cookie - the cookie that was returned when advise was called + */ + void unadvise(Class comEventCallbackInterface, final IComEventCallbackCookie cookie); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPointContainer.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPointContainer.java new file mode 100644 index 0000000000..7a95144bba --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPointContainer.java @@ -0,0 +1,21 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; + +@ComInterface(iid="{B196B284-BAB4-101A-B69C-00AA00341D07}") +public interface IConnectionPointContainer extends IRawDispatchHandle { + +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IDispatch.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IDispatch.java new file mode 100644 index 0000000000..f3d57b0179 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IDispatch.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +/** + * Java friendly version of {@link com.sun.jna.platform.win32.COM.IDispatch}. + * + */ +public interface IDispatch extends IUnknown { + + void setProperty(String name, T value); + T getProperty(Class returnType, String name, Object... args); + T invokeMethod(Class returnType, String name, Object... args); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRawDispatchHandle.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRawDispatchHandle.java new file mode 100644 index 0000000000..b7219cf088 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRawDispatchHandle.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.IDispatch; + +/** + * IF you want to access the underlying raw (com.sun.jna.platform.win32.COM.IDispatch) object + * then have your @ComObject or @ComInterface interface extends this interface. + * + */ +public interface IRawDispatchHandle { + IDispatch getRawDispatch(); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRunningObjectTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRunningObjectTable.java new file mode 100644 index 0000000000..6ddc37b401 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IRunningObjectTable.java @@ -0,0 +1,41 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.util.List; + +/** + * Java friendly version of + * {@link com.sun.jna.platform.win32.COM.IRunningObjectTable} + * + */ +public interface IRunningObjectTable { + + /** + * Creates and returns an enumerator of all the objects currently registered + * in the running object table (ROT). + * + */ + Iterable enumRunning(); + + /** + * Gets all the active (running) objects that support the give interface. + * + * Enumerates the running objects (via enumRunning), and returns a list of + * those for which queryInterface(iid) gives a valid result. + * + * @param iid + * @return + */ + List getActiveObjectsByInterface(Class comInterface); +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IUnknown.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IUnknown.java new file mode 100644 index 0000000000..32720ab001 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/IUnknown.java @@ -0,0 +1,35 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; + +/** + * Java friendly version of the IUnknown interface. + * + * + */ +@ComInterface(iid="{00000000-0000-0000-C000-000000000046}") +public interface IUnknown { + /** + * Returns a proxy object for the given interface. Assuming that the + * interface is annotated with a ComInterface annotation that provides a + * valid iid. + * + * Will throw COMException if an error occurs trying to retrieve the requested interface, + * see exception cause for details. + * + */ + T queryInterface(Class comInterface) throws COMException; +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java new file mode 100644 index 0000000000..1aca3177ae --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java @@ -0,0 +1,648 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; +import java.util.Date; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import com.sun.jna.Pointer; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.Guid; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.Kernel32Util; +import com.sun.jna.platform.win32.OaIdl; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.OleAuto; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.Variant; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.Variant.VariantArg; +import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.platform.win32.COM.ConnectionPoint; +import com.sun.jna.platform.win32.COM.ConnectionPointContainer; +import com.sun.jna.platform.win32.COM.Dispatch; +import com.sun.jna.platform.win32.COM.IDispatch; +import com.sun.jna.platform.win32.COM.IDispatchCallback; +import com.sun.jna.platform.win32.COM.Unknown; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; + +/** + * This object acts as the invocation handler for interfaces annotated with + * ComInterface. It wraps all (necessary) low level COM calls and executes them + * on a 'ComThread' held by the Factory object. + */ +public class ProxyObject implements InvocationHandler, com.sun.jna.platform.win32.COM.util.IDispatch, + IRawDispatchHandle { + + public ProxyObject(Class theInterface, IDispatch rawDispatch, Factory factory) { + this.unknownId = -1; + this.rawDispatch = rawDispatch; + this.comThread = factory.getComThread(); + this.theInterface = theInterface; + this.factory = factory; + // make sure dispatch object knows we have a reference to it + // (for debug it is usefult to be able to see how many refs are present + int n = this.rawDispatch.AddRef(); + this.getUnknownId(); // pre cache/calculate it + factory.register(this); + } + + /** when proxy is created for arguments on a call back, they are already on the + * com thread, and hence calling 'getUnknownId' will not work as it uses the ComThread + * however, the unknown pointer value is passed in; + * + * @param theInterface + * @param rawUnk + * @param rawDispatch + * @param factory + */ + ProxyObject(Class theInterface, long unknownId, IDispatch rawDispatch, Factory factory) { + this.unknownId = unknownId; + this.rawDispatch = rawDispatch; + this.comThread = factory.getComThread(); + this.theInterface = theInterface; + this.factory = factory; + // make sure dispatch object knows we have a reference to it + // (for debug it is usefult to be able to see how many refs are present + int n = this.rawDispatch.AddRef(); + factory.register(this); + } + + // cached value of the IUnknown interface pointer + // Rules of COM state that querying for the IUnknown interface must return + // an identical pointer value + long unknownId; + + long getUnknownId() { + if (-1 == this.unknownId) { + try { + + final PointerByReference ppvObject = new PointerByReference(); + + Thread current = Thread.currentThread(); + String tn = current.getName(); + + HRESULT hr = this.comThread.execute(new Callable() { + @Override + public HRESULT call() throws Exception { + IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN; + return ProxyObject.this.getRawDispatch().QueryInterface(new REFIID.ByValue(iid), ppvObject); + } + }); + + if (WinNT.S_OK.equals(hr)) { + Dispatch dispatch = new Dispatch(ppvObject.getValue()); + this.unknownId = Pointer.nativeValue(dispatch.getPointer()); + // QueryInterface returns a COM object pointer with a +1 + // reference, we must drop one, + // Note: createProxy adds one; + int n = dispatch.Release(); + } else { + String formatMessageFromHR = Kernel32Util.formatMessage(hr); + throw new COMException("getUnknownId: " + formatMessageFromHR); + } + } catch (Exception e) { + throw new COMException("Error occured when trying get Unknown Id ", e); + } + } + return this.unknownId; + } + + @Override + protected void finalize() throws Throwable { + this.dispose(1); + } + + public void dispose(int r) { + if (((Dispatch) this.rawDispatch).getPointer().equals(Pointer.NULL)) { + // do nothing, already disposed + } else { + for (int i = 0; i < r; ++i) { + // catch result to help with debug + int n = this.rawDispatch.Release(); + int n2 = n; + } + this.factory.unregister(this, r); + ((Dispatch) this.rawDispatch).setPointer(Pointer.NULL); + } + } + + Class theInterface; + Factory factory; + ComThread comThread; + com.sun.jna.platform.win32.COM.IDispatch rawDispatch; + + public com.sun.jna.platform.win32.COM.IDispatch getRawDispatch() { + return this.rawDispatch; + } + + // -------------------- Object ------------------------- + + /* + * The QueryInterface rule state that 'a call to QueryInterface with + * IID_IUnknown must always return the same physical pointer value.' + * + * [http://msdn.microsoft.com/en-us/library/ms686590%28VS.85%29.aspx] + * + * therefore we can compare the pointers + */ + public boolean equals(Object arg) { + if (null == arg) { + return false; + } else if (arg instanceof ProxyObject) { + ProxyObject other = (ProxyObject) arg; + return this.getUnknownId() == other.getUnknownId(); + } else if (Proxy.isProxyClass(arg.getClass())) { + InvocationHandler handler = Proxy.getInvocationHandler(arg); + if (handler instanceof ProxyObject) { + try { + ProxyObject other = (ProxyObject) handler; + return this.getUnknownId() == other.getUnknownId(); + } catch (Exception e) { + // if can't do this comparison, return false + // (queryInterface may throw if COM objects become invalid) + return false; + } + } else { + return false; + } + } else { + return false; + } + }; + + @Override + public int hashCode() { + return Long.valueOf(this.getUnknownId()).intValue(); + // this returns the native pointer peer value + // return this.getRawDispatch().hashCode(); + } + + @Override + public String toString() { + return this.theInterface.getName() + "{unk=" + this.hashCode() + "}"; + } + + // --------------------- InvocationHandler ----------------------------- + @Override + public Object invoke(final Object proxy, final java.lang.reflect.Method method, final Object[] args) + throws Throwable { + return this.invokeSynchronised(proxy, method, args); + } + + /* + * may not necessary for this method to be synchronised as all calls to COM + * are on their own , single, thread. However, might be best not to overlap + * calls to COM object with advise, unadvise, queryInterface, etc. + */ + synchronized Object invokeSynchronised(final Object proxy, final java.lang.reflect.Method method, + final Object[] args) throws Throwable { + if (method.equals(Object.class.getMethod("toString"))) { + return this.toString(); + } else if (method.equals(Object.class.getMethod("equals", Object.class))) { + return this.equals(args[0]); + } else if (method.equals(Object.class.getMethod("hashCode"))) { + return this.hashCode(); + } else if (method.equals(IRawDispatchHandle.class.getMethod("getRawDispatch"))) { + return this.getRawDispatch(); + } else if (method.equals(IUnknown.class.getMethod("queryInterface", Class.class))) { + return this.queryInterface((Class) args[0]); + } else if (method.equals(IConnectionPoint.class.getMethod("advise", Class.class, + IComEventCallbackListener.class))) { + return this.advise((Class) args[0], (IComEventCallbackListener) args[1]); + } else if (method.equals(IConnectionPoint.class.getMethod("unadvise", Class.class, + IComEventCallbackCookie.class))) { + this.unadvise((Class) args[0], (IComEventCallbackCookie) args[1]); + return null; + } + + Class returnType = method.getReturnType(); + boolean isVoid = Void.TYPE.equals(returnType); + + ComProperty prop = method.getAnnotation(ComProperty.class); + if (null != prop) { + if (isVoid) { + String propName = this.getMutatorName(method, prop); + this.setProperty(propName, args[0]); + return null; + } else { + String propName = this.getAccessorName(method, prop); + return this.getProperty(returnType, propName, args); + } + } + + ComMethod meth = method.getAnnotation(ComMethod.class); + if (null != meth) { + String methName = this.getMethodName(method, meth); + Object res = this.invokeMethod(returnType, methName, args); + return res; + } + + return null; + } + + // ---------------------- IConnectionPoint ---------------------- + ConnectionPoint fetchRawConnectionPoint(IID iid) throws InterruptedException, ExecutionException, TimeoutException { + // query for ConnectionPointContainer + IConnectionPointContainer cpc = this.queryInterface(IConnectionPointContainer.class); + Dispatch rawCpcDispatch = (Dispatch) cpc.getRawDispatch(); + final ConnectionPointContainer rawCpc = new ConnectionPointContainer(rawCpcDispatch.getPointer()); + + // find connection point for comEventCallback interface + final REFIID adviseRiid = new REFIID(iid.getPointer()); + final PointerByReference ppCp = new PointerByReference(); + HRESULT hr = factory.getComThread().execute(new Callable() { + @Override + public HRESULT call() throws Exception { + return rawCpc.FindConnectionPoint(adviseRiid, ppCp); + } + }); + COMUtils.checkRC(hr); + final ConnectionPoint rawCp = new ConnectionPoint(ppCp.getValue()); + return rawCp; + } + + public IComEventCallbackCookie advise(Class comEventCallbackInterface, + final IComEventCallbackListener comEventCallbackListener) { + try { + ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class); + if (null == comInterfaceAnnotation) { + throw new COMException( + "advise: Interface must define a value for either iid via the ComInterface annotation"); + } + final IID iid = this.getIID(comInterfaceAnnotation); + + final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid); + + // create the dispatch listener + final IDispatchCallback rawListener = new CallbackProxy(this.factory, comEventCallbackInterface, + comEventCallbackListener); + // store it the comEventCallback argument, so it is not garbage + // collected. + comEventCallbackListener.setDispatchCallbackListener(rawListener); + // set the dispatch listener to listen to events from the connection + // point + final DWORDByReference pdwCookie = new DWORDByReference(); + HRESULT hr = factory.getComThread().execute(new Callable() { + @Override + public HRESULT call() throws Exception { + return rawCp.Advise(rawListener, pdwCookie); + } + }); + int n = rawCp.Release(); // release before check in case check + // throws exception + COMUtils.checkRC(hr); + + // return the cookie so that a call to stop listening can be made + return new ComEventCallbackCookie(pdwCookie.getValue()); + + } catch (Exception e) { + throw new COMException("Error occured in advise when trying to connect the listener " + + comEventCallbackListener, e); + } + } + + public void unadvise(Class comEventCallbackInterface, final IComEventCallbackCookie cookie) { + try { + ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class); + if (null == comInterfaceAnnotation) { + throw new COMException( + "unadvise: Interface must define a value for iid via the ComInterface annotation"); + } + IID iid = this.getIID(comInterfaceAnnotation); + + final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid); + + HRESULT hr = factory.getComThread().execute(new Callable() { + @Override + public HRESULT call() throws Exception { + return rawCp.Unadvise(((ComEventCallbackCookie) cookie).getValue()); + } + }); + + rawCp.Release(); + COMUtils.checkRC(hr); + + } catch (Exception e) { + throw new COMException("Error occured in unadvise when trying to disconnect the listener from " + this, e); + } + } + + // --------------------- IDispatch ------------------------------ + @Override + public void setProperty(String name, T value) { + VARIANT v = Convert.toVariant(value); + WinNT.HRESULT hr = this.oleMethod(OleAuto.DISPATCH_PROPERTYPUT, null, this.getRawDispatch(), name, v); + COMUtils.checkRC(hr); + } + + @Override + public T getProperty(Class returnType, String name, Object... args) { + VARIANT[] vargs; + if (null == args) { + vargs = new VARIANT[0]; + } else { + vargs = new VARIANT[args.length]; + } + for (int i = 0; i < vargs.length; ++i) { + vargs[i] = Convert.toVariant(args[i]); + } + Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference(); + WinNT.HRESULT hr = this.oleMethod(OleAuto.DISPATCH_PROPERTYGET, result, this.getRawDispatch(), name, vargs); + COMUtils.checkRC(hr); + Object jobj = Convert.toJavaObject(result); + if (IComEnum.class.isAssignableFrom(returnType)) { + return (T) Convert.toComEnum((Class) returnType, jobj); + } + if (jobj instanceof IDispatch) { + IDispatch d = (IDispatch) jobj; + T t = this.factory.createProxy(returnType, d); + // must release a COM reference, createProxy adds one, as does the + // call + int n = d.Release(); + return t; + } + return (T) jobj; + } + + @Override + public T invokeMethod(Class returnType, String name, Object... args) { + VARIANT[] vargs; + if (null == args) { + vargs = new VARIANT[0]; + } else { + vargs = new VARIANT[args.length]; + } + for (int i = 0; i < vargs.length; ++i) { + vargs[i] = Convert.toVariant(args[i]); + } + Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference(); + WinNT.HRESULT hr = this.oleMethod(OleAuto.DISPATCH_METHOD, result, this.getRawDispatch(), name, vargs); + COMUtils.checkRC(hr); + + Object jobj = Convert.toJavaObject(result); + if (IComEnum.class.isAssignableFrom(returnType)) { + return (T) Convert.toComEnum((Class) returnType, jobj); + } + if (jobj instanceof IDispatch) { + IDispatch d = (IDispatch) jobj; + T t = this.factory.createProxy(returnType, d); + // must release a COM reference, createProxy adds one, as does the + // call + int n = d.Release(); + return t; + } + return (T) jobj; + } + + @Override + public T queryInterface(Class comInterface) throws COMException { + try { + ComInterface comInterfaceAnnotation = comInterface.getAnnotation(ComInterface.class); + if (null == comInterfaceAnnotation) { + throw new COMException( + "queryInterface: Interface must define a value for iid via the ComInterface annotation"); + } + final IID iid = this.getIID(comInterfaceAnnotation); + final PointerByReference ppvObject = new PointerByReference(); + + HRESULT hr = this.comThread.execute(new Callable() { + @Override + public HRESULT call() throws Exception { + return ProxyObject.this.getRawDispatch().QueryInterface(new REFIID.ByValue(iid), ppvObject); + } + }); + + if (WinNT.S_OK.equals(hr)) { + Dispatch dispatch = new Dispatch(ppvObject.getValue()); + T t = this.factory.createProxy(comInterface, dispatch); + // QueryInterface returns a COM object pointer with a +1 + // reference, we must drop one, + // Note: createProxy adds one; + int n = dispatch.Release(); + return t; + } else { + String formatMessageFromHR = Kernel32Util.formatMessage(hr); + throw new COMException("queryInterface: " + formatMessageFromHR); + } + } catch (Exception e) { + throw new COMException("Error occured when trying to query for interface " + comInterface.getName(), e); + } + } + + IID getIID(ComInterface annotation) { + String iidStr = annotation.iid(); + if (null != iidStr && !iidStr.isEmpty()) { + return new IID(iidStr); + } else { + throw new COMException("ComInterface must define a value for iid"); + } + } + + // --------------------- ProxyObject --------------------- + + private String getAccessorName(java.lang.reflect.Method method, ComProperty prop) { + if (prop.name().isEmpty()) { + String methName = method.getName(); + if (methName.startsWith("get")) { + return methName.replaceFirst("get", ""); + } else { + throw new RuntimeException( + "Property Accessor name must start with 'get', or set the anotation 'name' value"); + } + } else { + return prop.name(); + } + } + + private String getMutatorName(java.lang.reflect.Method method, ComProperty prop) { + if (prop.name().isEmpty()) { + String methName = method.getName(); + if (methName.startsWith("set")) { + return methName.replaceFirst("set", ""); + } else { + throw new RuntimeException( + "Property Mutator name must start with 'set', or set the anotation 'name' value"); + } + } else { + return prop.name(); + } + } + + private String getMethodName(java.lang.reflect.Method method, ComMethod meth) { + if (meth.name().isEmpty()) { + String methName = method.getName(); + return methName; + } else { + return meth.name(); + } + } + + /** The Constant LOCALE_USER_DEFAULT. */ + public final static LCID LOCALE_USER_DEFAULT = Kernel32.INSTANCE.GetUserDefaultLCID(); + + /** The Constant LOCALE_SYSTEM_DEFAULT. */ + public final static LCID LOCALE_SYSTEM_DEFAULT = Kernel32.INSTANCE.GetSystemDefaultLCID(); + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, String name, VARIANT pArg) + throws COMException { + return this.oleMethod(nType, pvResult, pDisp, name, new VARIANT[] { pArg }); + } + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, DISPID dispId, VARIANT pArg) + throws COMException { + return this.oleMethod(nType, pvResult, pDisp, dispId, new VARIANT[] { pArg }); + } + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, String name) + throws COMException { + return this.oleMethod(nType, pvResult, pDisp, name, (VARIANT[]) null); + } + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, DISPID dispId) + throws COMException { + + return this.oleMethod(nType, pvResult, pDisp, dispId, (VARIANT[]) null); + } + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, final IDispatch pDisp, String name, + VARIANT[] pArgs) throws COMException { + try { + if (pDisp == null) + throw new COMException("pDisp (IDispatch) parameter is null!"); + + // variable declaration + final WString[] ptName = new WString[] { new WString(name) }; + final DISPIDByReference pdispID = new DISPIDByReference(); + + // Get DISPID for name passed... + HRESULT hr = this.comThread.execute(new Callable() { + @Override + public HRESULT call() throws Exception { + HRESULT hr = pDisp.GetIDsOfNames(new REFIID.ByValue(Guid.IID_NULL), ptName, 1, LOCALE_USER_DEFAULT, + pdispID); + return hr; + } + }); + COMUtils.checkRC(hr); + + return this.oleMethod(nType, pvResult, pDisp, pdispID.getValue(), pArgs); + } catch (InterruptedException e) { + throw new COMException(e); + } catch (ExecutionException e) { + throw new COMException(e); + } catch (TimeoutException e) { + throw new COMException(e); + } + } + + /* + * @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod + */ + protected HRESULT oleMethod(final int nType, final VARIANT.ByReference pvResult, final IDispatch pDisp, + final DISPID dispId, VARIANT[] pArgs) throws COMException { + + if (pDisp == null) + throw new COMException("pDisp (IDispatch) parameter is null!"); + + // variable declaration + int _argsLen = 0; + VARIANT[] _args = null; + final DISPPARAMS.ByReference dp = new DISPPARAMS.ByReference(); + final EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference(); + final IntByReference puArgErr = new IntByReference(); + + // make parameter reverse ordering as expected by COM runtime + if ((pArgs != null) && (pArgs.length > 0)) { + _argsLen = pArgs.length; + _args = new VARIANT[_argsLen]; + + int revCount = _argsLen; + for (int i = 0; i < _argsLen; i++) { + _args[i] = pArgs[--revCount]; + } + } + + // Handle special-case for property-puts! + if (nType == OleAuto.DISPATCH_PROPERTYPUT) { + dp.cNamedArgs = new UINT(_argsLen); + dp.rgdispidNamedArgs = new DISPIDByReference(OaIdl.DISPID_PROPERTYPUT); + } + + // Build DISPPARAMS + if (_argsLen > 0) { + dp.cArgs = new UINT(_args.length); + // make pointer of variant array + dp.rgvarg = new VariantArg.ByReference(_args); + + // write 'DISPPARAMS' structure to memory + dp.write(); + } + + // Make the call! + try { + + HRESULT hr = this.comThread.execute(new Callable() { + @Override + public HRESULT call() throws Exception { + return pDisp.Invoke(dispId, new REFIID.ByValue(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, + new WinDef.WORD(nType), dp, pvResult, pExcepInfo, puArgErr); + } + }); + + COMUtils.checkRC(hr, pExcepInfo, puArgErr); + return hr; + } catch (InterruptedException e) { + throw new COMException(e); + } catch (ExecutionException e) { + throw new COMException(e); + } catch (TimeoutException e) { + throw new COMException(e); + } + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java new file mode 100644 index 0000000000..874461378e --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java @@ -0,0 +1,83 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.ptr.PointerByReference; + +public class RunningObjectTable implements IRunningObjectTable { + + protected RunningObjectTable(com.sun.jna.platform.win32.COM.RunningObjectTable raw, Factory factory) { + this.raw = raw; + this.factory = factory; + this.comThread = factory.getComThread(); + } + + Factory factory; + ComThread comThread; + com.sun.jna.platform.win32.COM.RunningObjectTable raw; + + @Override + public Iterable enumRunning() { + + try { + + final PointerByReference ppenumMoniker = new PointerByReference(); + + WinNT.HRESULT hr = this.comThread.execute(new Callable() { + @Override + public WinNT.HRESULT call() throws Exception { + return RunningObjectTable.this.raw.EnumRunning(ppenumMoniker); + } + }); + COMUtils.checkRC(hr); + com.sun.jna.platform.win32.COM.EnumMoniker raw = new com.sun.jna.platform.win32.COM.EnumMoniker( + ppenumMoniker.getValue()); + + return new EnumMoniker(raw, this.raw, this.factory); + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + + } + + @Override + public List getActiveObjectsByInterface(Class comInterface) { + List result = new ArrayList(); + + for (IDispatch obj : this.enumRunning()) { + try { + T dobj = obj.queryInterface(comInterface); + + result.add(dobj); + } catch (COMException ex) { + + } + } + + return result; + } +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComEventCallback.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComEventCallback.java new file mode 100644 index 0000000000..ad72ce7ccc --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComEventCallback.java @@ -0,0 +1,27 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD }) +@Inherited +public @interface ComEventCallback { + int dispid() default -1; // default to dispid unknown + String name() default ""; +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComInterface.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComInterface.java new file mode 100644 index 0000000000..ff4f898c71 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComInterface.java @@ -0,0 +1,26 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +@Inherited +public @interface ComInterface { + String iid() default ""; +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComMethod.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComMethod.java new file mode 100644 index 0000000000..ce8e4e8c20 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComMethod.java @@ -0,0 +1,27 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD }) +@Inherited +public @interface ComMethod { + String name() default ""; + int dispId() default -1; //default to dispid unknown +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComObject.java new file mode 100644 index 0000000000..fea5158b75 --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComObject.java @@ -0,0 +1,27 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +@Inherited +public @interface ComObject { + String clsId() default ""; + String progId() default ""; +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComProperty.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComProperty.java new file mode 100644 index 0000000000..6104c1dbaa --- /dev/null +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/annotation/ComProperty.java @@ -0,0 +1,26 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD }) +@Inherited +public @interface ComProperty { + String name() default ""; +} diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Guid.java b/contrib/platform/src/com/sun/jna/platform/win32/Guid.java index bcf7ca358a..7427dfbe39 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Guid.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Guid.java @@ -37,6 +37,21 @@ public interface Guid { */ public static class GUID extends Structure { + public static class ByValue extends GUID implements Structure.ByValue { + public ByValue() {} + public ByValue(GUID guid) { + super(guid.getPointer()); + + Data1 = guid.Data1; + Data2 = guid.Data2; + Data3 = guid.Data3; + Data4 = guid.Data4; + } + public ByValue(Pointer memory) { + super(memory); + } + } + /** * The Class ByReference. * diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Ole32.java b/contrib/platform/src/com/sun/jna/platform/win32/Ole32.java index aa6b32b220..e344d394c3 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Ole32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Ole32.java @@ -15,9 +15,9 @@ import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.WString; -import com.sun.jna.platform.win32.BaseTSD.SIZE_T; import com.sun.jna.platform.win32.Guid.CLSID; import com.sun.jna.platform.win32.Guid.GUID; +import com.sun.jna.platform.win32.WinDef.DWORD; import com.sun.jna.platform.win32.WinDef.LPVOID; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.PointerByReference; @@ -257,7 +257,7 @@ HRESULT CoCreateInstance(GUID rclsid, Pointer pUnkOuter, int dwClsContext, * @return If the function succeeds, it returns the reallocated memory block. Otherwise, it returns NULL. */ Pointer CoTaskMemRealloc(Pointer pv, long cb); - + /** * Frees a block of task memory previously allocated through a call to the {@link #CoTaskMemAlloc} or * {@link #CoTaskMemRealloc} function. The function uses the default OLE allocator. The number of bytes @@ -267,4 +267,62 @@ HRESULT CoCreateInstance(GUID rclsid, Pointer pUnkOuter, int dwClsContext, */ void CoTaskMemFree(Pointer pv); + /** + * Retrieves a pointer to the default OLE task memory allocator. + * + * {@code + * HRESULT CoGetMalloc( + * [In] DWORD dwMemContext, + * [Out] LPMALLOC *ppMalloc + * ); + * + * @see MSDN + * + */ + HRESULT CoGetMalloc(DWORD dwMemContext, PointerByReference ppMalloc); + + /** + * Returns a pointer to the IRunningObjectTable interface on the local running object table (ROT). + * + * {@code + * HRESULT GetRunningObjectTable( + * [In] DWORD reserved, + * [Out] LPRUNNINGOBJECTTABLE *pprot + * ); + * } + * + * + * @see MSDN + */ + HRESULT GetRunningObjectTable(DWORD reserved, PointerByReference pprot); + + /** + * Returns a pointer to an implementation of IBindCtx (a bind context object). + * + * {@code + * HRESULT CreateBindCtx( + * [In] DWORD reserved, + * [Out] LPBC *ppbc + * ); + * } + * + * + * @see MSDN + */ + HRESULT CreateBindCtx(DWORD reserved, PointerByReference ppbc); + + /** + * Determines whether a remote object is connected to the corresponding in-process object. + * + * {@code + * BOOL CoIsHandlerConnected( + * [In] LPUNKNOWN pUnk + * ); + * } + * + * @see MSDN + * + */ + boolean CoIsHandlerConnected(Pointer pUnk); + } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Variant.java b/contrib/platform/src/com/sun/jna/platform/win32/Variant.java index 37a6870501..1d3a897425 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Variant.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Variant.java @@ -692,6 +692,13 @@ public ByReference(VARIANT[] variantArg) { public VariantArg() { } + /** + * construct VariantArg cast onto pre-allocated memory + */ + public VariantArg(Pointer pointer) { + super(pointer); + } + public VariantArg(VARIANT[] variantArg) { this.variantArg = variantArg; } @@ -700,5 +707,12 @@ public VariantArg(VARIANT[] variantArg) { protected List getFieldOrder() { return Arrays.asList(new String[] { "variantArg" }); } + + public void setArraySize(int size) { + this.variantArg = new VARIANT[size]; + this.read(); + } + + } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/ComEventCallbacks_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/ComEventCallbacks_Test.java new file mode 100644 index 0000000000..a059e905a5 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/ComEventCallbacks_Test.java @@ -0,0 +1,204 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.Pointer; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.Guid; +import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.User32; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.platform.win32.WinUser; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; + +public class ComEventCallbacks_Test { + + final String WORD_APPLICATION_INTERFACE = "{00020970-0000-0000-C000-000000000046}"; + final String APPLICATION_EVENTS_4 = "{00020A01-0000-0000-C000-000000000046}"; + + @Before + public void before() { + HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED); + COMUtils.checkRC(hr); + } + + @After + public void after() { + Ole32.INSTANCE.CoUninitialize(); + } + + class Application_Events4 implements IDispatchCallback { + public DispatchListener listener = new DispatchListener(this); + + @Override + public Pointer getPointer() { + return this.listener.getPointer(); + } + + //------------------------ IDispatch ------------------------------ + @Override + public HRESULT GetTypeInfoCount(UINTByReference pctinfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, PointerByReference ppTInfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, DISPIDByReference rgDispId) { + return new HRESULT(WinError.E_NOTIMPL); + } + + public boolean Invoke_called = false; + @Override + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, + WORD wFlags, DISPPARAMS.ByReference pDispParams, + VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, + IntByReference puArgErr) { + this.Invoke_called = true; + + return new HRESULT(WinError.E_NOTIMPL); + } + + + //------------------------ IUnknown ------------------------------ + public boolean QueryInterface_called = false; + @Override + public HRESULT QueryInterface(REFIID.ByValue refid, PointerByReference ppvObject) { + this.QueryInterface_called = true; + if (null==ppvObject) { + return new HRESULT(WinError.E_POINTER); + } + + String s = refid.toGuidString(); + IID appEvnts4 = new IID(APPLICATION_EVENTS_4); + REFIID.ByValue riid = new REFIID.ByValue(appEvnts4.getPointer()); + + if (refid.equals(riid)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Unknown.IID_IUNKNOWN)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Dispatch.IID_IDISPATCH)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + return new HRESULT(WinError.E_NOINTERFACE); + } + + public int AddRef() { + return 0; + } + + public int Release() { + return 0; + } + + } + + @Test + public void cause_Quit_Event() { + // Create word object + CLSID clsid = new CLSID("{000209FF-0000-0000-C000-000000000046}"); + PointerByReference ppWordApp = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE + .CoCreateInstance(clsid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, ppWordApp); +// HRESULT hr =OleAuto.INSTANCE.GetActiveObject(clsid, null, ppWordApp); + COMUtils.checkRC(hr); + + // query for ConnectionPointContainer + Unknown unk = new Unknown(ppWordApp.getValue()); + PointerByReference ppCpc = new PointerByReference(); + IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}"); + hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc); + COMUtils.checkRC(hr); + ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue()); + + // find connection point for Application_Events4 + IID appEvnts4 = new IID(APPLICATION_EVENTS_4); + REFIID riid = new REFIID(appEvnts4.getPointer()); + PointerByReference ppCp = new PointerByReference(); + hr = cpc.FindConnectionPoint(riid, ppCp); + COMUtils.checkRC(hr); + final ConnectionPoint cp = new ConnectionPoint(ppCp.getValue()); + IID cp_iid = new IID(); + hr = cp.GetConnectionInterface(cp_iid); + COMUtils.checkRC(hr); + + final Application_Events4 listener = new Application_Events4(); + final DWORDByReference pdwCookie = new DWORDByReference(); + HRESULT hr1 = cp.Advise(listener, pdwCookie); + COMUtils.checkRC(hr1); + +// Assert.assertTrue(listener.QueryInterface_called); +// + // Call Quit + Dispatch d = new Dispatch(ppWordApp.getValue()); + DISPID dispIdMember = new DISPID(1105); // Quit + REFIID.ByValue niid = new REFIID.ByValue(Guid.IID_NULL); + LCID lcid = Kernel32.INSTANCE.GetSystemDefaultLCID(); + WinDef.WORD wFlags = new WinDef.WORD(1); + DISPPARAMS.ByReference pDispParams = new DISPPARAMS.ByReference(); + VARIANT.ByReference pVarResult = new VARIANT.ByReference(); + IntByReference puArgErr = new IntByReference(); + EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference(); + hr = d.Invoke(dispIdMember, niid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); + COMUtils.checkRC(hr); + + //Wait for event to happen + try { + Thread.sleep(200); +// WinUser.MSG msg = new WinUser.MSG(); +// while (((User32.INSTANCE.GetMessage(msg, null, 0, 0)) != 0)) { +// User32.INSTANCE.TranslateMessage(msg); +// User32.INSTANCE.DispatchMessage(msg); +// } + } catch (Exception e) { + e.printStackTrace(); + } + + Assert.assertTrue(listener.Invoke_called); + } + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/ConnectionPointContainer_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/ConnectionPointContainer_Test.java new file mode 100644 index 0000000000..8b1ea575fa --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/ConnectionPointContainer_Test.java @@ -0,0 +1,242 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.Pointer; +import com.sun.jna.WString; +import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.OaIdl; +import com.sun.jna.platform.win32.OaIdl.DISPID; +import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; +import com.sun.jna.platform.win32.OaIdl.EXCEPINFO; +import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; +import com.sun.jna.platform.win32.Guid; +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.OleAuto; +import com.sun.jna.platform.win32.Variant; +import com.sun.jna.platform.win32.WTypes; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.Variant.VARIANT; +import com.sun.jna.platform.win32.WinDef.DWORDByReference; +import com.sun.jna.platform.win32.WinDef.LCID; +import com.sun.jna.platform.win32.WinDef.UINT; +import com.sun.jna.platform.win32.WinDef.UINTByReference; +import com.sun.jna.platform.win32.WinDef.WORD; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; + +public class ConnectionPointContainer_Test { + + PointerByReference ppWordApp; + + @Before + public void before() { + HRESULT hr = Ole32.INSTANCE.CoInitialize(null); + COMUtils.checkRC(hr); + + // Create word object + CLSID clsid = new CLSID("{000209FF-0000-0000-C000-000000000046}"); + this.ppWordApp = new PointerByReference(); + hr = Ole32.INSTANCE + .CoCreateInstance(clsid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, this.ppWordApp); + COMUtils.checkRC(hr); + } + + @After + public void after() { + // Close Word + Dispatch d = new Dispatch(this.ppWordApp.getValue()); + DISPID dispIdMember = new DISPID(1105); // Quit + REFIID.ByValue riid = new REFIID.ByValue(Guid.IID_NULL); + LCID lcid = Kernel32.INSTANCE.GetSystemDefaultLCID(); + WinDef.WORD wFlags = new WinDef.WORD(1); + DISPPARAMS.ByReference pDispParams = new DISPPARAMS.ByReference(); + VARIANT.ByReference pVarResult = new VARIANT.ByReference(); + IntByReference puArgErr = new IntByReference(); + EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference(); + d.Invoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); + + Ole32.INSTANCE.CoUninitialize(); + } + + @Test + public void queryInterface_ConnectionPointContainer() { + Unknown unk = new Unknown(this.ppWordApp.getValue()); + PointerByReference ppCpc = new PointerByReference(); + IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}"); + HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc); + COMUtils.checkRC(hr); + ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue()); + } + + @Test + public void FindConnectionPoint() { + // query for ConnectionPointContainer + Unknown unk = new Unknown(this.ppWordApp.getValue()); + PointerByReference ppCpc = new PointerByReference(); + IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}"); + HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc); + COMUtils.checkRC(hr); + ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue()); + + // find connection point for Application_Events4 + IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}"); + REFIID riid = new REFIID(appEvnts4.getPointer()); + PointerByReference ppCp = new PointerByReference(); + hr = cpc.FindConnectionPoint(riid, ppCp); + COMUtils.checkRC(hr); + ConnectionPoint cp = new ConnectionPoint(ppCp.getValue()); + } + + @Test + public void GetConnectionInterface() { + // query for ConnectionPointContainer + Unknown unk = new Unknown(this.ppWordApp.getValue()); + PointerByReference ppCpc = new PointerByReference(); + IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}"); + HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc); + COMUtils.checkRC(hr); + ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue()); + + // find connection point for Application_Events4 + IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}"); + REFIID riid = new REFIID(appEvnts4.getPointer()); + PointerByReference ppCp = new PointerByReference(); + hr = cpc.FindConnectionPoint(riid, ppCp); + COMUtils.checkRC(hr); + ConnectionPoint cp = new ConnectionPoint(ppCp.getValue()); + + IID cp_iid = new IID(); + hr = cp.GetConnectionInterface(cp_iid); + COMUtils.checkRC(hr); + + Assert.assertEquals(appEvnts4, cp_iid); + } + + class Application_Events4 implements IDispatchCallback { + public DispatchListener listener = new DispatchListener(this); + + @Override + public Pointer getPointer() { + return this.listener.getPointer(); + } + + //------------------------ IDispatch ------------------------------ + @Override + public HRESULT GetTypeInfoCount(UINTByReference pctinfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid, PointerByReference ppTInfo) { + return new HRESULT(WinError.E_NOTIMPL); + } + + @Override + public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid, DISPIDByReference rgDispId) { + return new HRESULT(WinError.E_NOTIMPL); + } + + public boolean Invoke_called = false; + @Override + public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags, + DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo, + IntByReference puArgErr) { + this.Invoke_called = true; + return new HRESULT(WinError.E_NOTIMPL); + } + + + //------------------------ IUnknown ------------------------------ + public boolean QueryInterface_called = false; + @Override + public HRESULT QueryInterface(REFIID.ByValue refid, PointerByReference ppvObject) { + this.QueryInterface_called = true; + if (null==ppvObject) { + return new HRESULT(WinError.E_POINTER); + } + + String s = refid.toGuidString(); + IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}"); + REFIID.ByValue riid = new REFIID.ByValue(appEvnts4.getPointer()); + + if (refid.equals(riid)) { + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Unknown.IID_IUNKNOWN)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + if (new Guid.IID(refid.getPointer()).equals(Dispatch.IID_IDISPATCH)) { + ppvObject.setValue(this.getPointer()); + return WinError.S_OK; + } + + return new HRESULT(WinError.E_NOINTERFACE); + } + + public int AddRef() { + return 0; + } + + public int Release() { + return 0; + } + + } + + @Test + public void Advise() { + + // query for ConnectionPointContainer + Unknown unk = new Unknown(this.ppWordApp.getValue()); + PointerByReference ppCpc = new PointerByReference(); + IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}"); + HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc); + COMUtils.checkRC(hr); + ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue()); + + // find connection point for Application_Events4 + IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}"); + REFIID riid = new REFIID(appEvnts4.getPointer()); + PointerByReference ppCp = new PointerByReference(); + hr = cpc.FindConnectionPoint(riid, ppCp); + COMUtils.checkRC(hr); + ConnectionPoint cp = new ConnectionPoint(ppCp.getValue()); + IID cp_iid = new IID(); + hr = cp.GetConnectionInterface(cp_iid); + COMUtils.checkRC(hr); + + Application_Events4 listener = new Application_Events4(); + + DWORDByReference pdwCookie = new DWORDByReference(); + hr = cp.Advise(listener, pdwCookie); + COMUtils.checkRC(hr); + + Assert.assertTrue(listener.QueryInterface_called); + + } + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/EnumMoniker_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/EnumMoniker_Test.java new file mode 100644 index 0000000000..102ccf9bca --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/EnumMoniker_Test.java @@ -0,0 +1,233 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.ULONG; +import com.sun.jna.platform.win32.WinDef.ULONGByReference; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.platform.win32.COM.util.Factory; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; +import com.sun.jna.ptr.PointerByReference; + +public class EnumMoniker_Test { + + @ComInterface(iid="{00020970-0000-0000-C000-000000000046}") + interface Application { + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComMethod + void Quit(); + } + + @ComObject(progId="Word.Application") + interface MsWordApp extends Application { + } + + Factory factory; + MsWordApp ob1; + MsWordApp ob2; + + @Before + public void before() { + this.factory = new Factory(); + // Two COM objects are require to be running for these tests to work + this.ob1 = this.factory.createObject(MsWordApp.class); + this.ob2 = this.factory.createObject(MsWordApp.class); + + WinNT.HRESULT hr = Ole32.INSTANCE.CoInitialize(null); + COMUtils.checkRC(hr); + } + + @After + public void after() { + ob1.Quit(); + ob2.Quit(); + Ole32.INSTANCE.CoUninitialize(); + } + + @Test + public void Reset() { + // GetRunningObjectTable + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + // EnumRunning + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue()); + + // Reset + hr = iterator.Reset(); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt1 = new PointerByReference(); + ULONGByReference pceltFetched1 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt1, pceltFetched1); + COMUtils.checkRC(hr); + + // Reset + hr = iterator.Reset(); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt2 = new PointerByReference(); + ULONGByReference pceltFetched2 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt2, pceltFetched2); + COMUtils.checkRC(hr); + + assertEquals(rgelt1.getValue(), rgelt2.getValue()); + } + + @Test + public void Next() { + // GetRunningObjectTable + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + // EnumRunning + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue()); + + // Reset + hr = iterator.Reset(); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt1 = new PointerByReference(); + ULONGByReference pceltFetched1 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt1, pceltFetched1); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt2 = new PointerByReference(); + ULONGByReference pceltFetched2 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt2, pceltFetched2); + COMUtils.checkRC(hr); + + assertNotEquals(rgelt1.getValue(), rgelt2.getValue()); + } + + @Test + public void Skip() { + // GetRunningObjectTable + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + // EnumRunning + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue()); + + // Reset + hr = iterator.Reset(); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt1 = new PointerByReference(); + ULONGByReference pceltFetched1 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt1, pceltFetched1); + COMUtils.checkRC(hr); + + // Reset + hr = iterator.Reset(); + COMUtils.checkRC(hr); + + // Skip + hr = iterator.Skip(new ULONG(1)); + COMUtils.checkRC(hr); + + // Next + PointerByReference rgelt2 = new PointerByReference(); + ULONGByReference pceltFetched2 = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt2, pceltFetched2); + COMUtils.checkRC(hr); + + assertNotEquals(rgelt1.getValue(), rgelt2.getValue()); + } + + @Test + public void Clone() { + // GetRunningObjectTable + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + // EnumRunning + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + IEnumMoniker iterator1 = new EnumMoniker(ppenumMoniker.getValue()); + + // iterator1.Reset + hr = iterator1.Reset(); + COMUtils.checkRC(hr); + + // iterator1.Next + PointerByReference rgelt1 = new PointerByReference(); + ULONGByReference pceltFetched1 = new ULONGByReference(); + hr = iterator1.Next(new ULONG(1), rgelt1, pceltFetched1); + COMUtils.checkRC(hr); + + // iterator1.Clone + PointerByReference ppenum = new PointerByReference(); + hr = iterator1.Clone(ppenum); + COMUtils.checkRC(hr); + IEnumMoniker iterator2 = new EnumMoniker(ppenum.getValue()); + + // iterator2.Next + PointerByReference rgelt2 = new PointerByReference(); + ULONGByReference pceltFetched2 = new ULONGByReference(); + hr = iterator2.Next(new ULONG(1), rgelt2, pceltFetched2); + COMUtils.checkRC(hr); + + assertNotEquals(rgelt1.getValue(), rgelt2.getValue()); + + // iterator1.Next + rgelt1 = new PointerByReference(); + pceltFetched1 = new ULONGByReference(); + hr = iterator1.Next(new ULONG(1), rgelt1, pceltFetched1); + COMUtils.checkRC(hr); + + assertEquals(rgelt1.getValue(), rgelt2.getValue()); + } + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/IDispatchTest.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/IDispatchTest.java index 746a388643..6df3845f9a 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/IDispatchTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/IDispatchTest.java @@ -16,6 +16,7 @@ import com.sun.jna.WString; import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.OaIdl.DISPIDByReference; import com.sun.jna.platform.win32.OleAuto.DISPPARAMS; import com.sun.jna.platform.win32.Guid; @@ -101,7 +102,7 @@ public void testGetIDsOfNames() { WString[] ptName = new WString[] { new WString("Application") }; DISPIDByReference pdispID = new DISPIDByReference(); - HRESULT hr = dispatch.GetIDsOfNames(Guid.IID_NULL, ptName, 1, LOCALE_SYSTEM_DEFAULT, pdispID); + HRESULT hr = dispatch.GetIDsOfNames(new REFIID.ByValue(Guid.IID_NULL), ptName, 1, LOCALE_SYSTEM_DEFAULT, pdispID); COMUtils.checkRC(hr); assertEquals(0, hr.intValue()); } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/IUnknownTest.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/IUnknownTest.java index 5c8a6b6146..33d65e9456 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/IUnknownTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/IUnknownTest.java @@ -15,6 +15,7 @@ import junit.framework.TestCase; import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.Guid.REFIID; import com.sun.jna.platform.win32.Ole32; import com.sun.jna.platform.win32.W32Errors; import com.sun.jna.platform.win32.WTypes; @@ -65,7 +66,7 @@ protected void setUp() throws Exception { public void testQueryInterface() { Unknown iUnknown = this.createIUnknown(); PointerByReference ppvObject = new PointerByReference(); - iUnknown.QueryInterface(IUnknown.IID_IUNKNOWN, ppvObject); + iUnknown.QueryInterface(new REFIID.ByValue(IUnknown.IID_IUNKNOWN), ppvObject); assertTrue("ppvObject:" + ppvObject.toString(), ppvObject != null); } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/RunningObjectTable_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/RunningObjectTable_Test.java new file mode 100644 index 0000000000..c3f17d3df0 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/RunningObjectTable_Test.java @@ -0,0 +1,182 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.WTypes.BSTRByReference; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.ULONG; +import com.sun.jna.platform.win32.WinDef.ULONGByReference; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinNT.HRESULT; +import com.sun.jna.ptr.PointerByReference; + +public class RunningObjectTable_Test { + + @Before + public void before() { + HRESULT hr = Ole32.INSTANCE.CoInitialize(null); + COMUtils.checkRC(hr); + } + + @After + public void after() { + Ole32.INSTANCE.CoUninitialize(); + } + + @Test + public void GetRunningObjectTable() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + + assertNotNull(pprot.getValue()); + } + + @Test + public void Register() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + //Can't yet be tested as IMoniker is not fully implemented + //rot.Register(grfFlags, punkObject, pmkObjectName, pdwRegister); + + } + + @Test + public void Revoke() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + //Can't yet be tested as IMoniker is not fully implemented, + // so we can't register an object, and hence can't get a registration key to Revoke one + //rot.Revoke(dwRegister); + + } + + @Test + public void IsRunning() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + //Can't yet be tested as IMoniker is not fully implemented, + //rot.IsRunning(pmkObjectName); + + } + + @Test + public void GetObject() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue()); + + iterator.Reset(); + + PointerByReference rgelt = new PointerByReference(); + ULONGByReference pceltFetched = new ULONGByReference(); + hr = iterator.Next(new ULONG(1), rgelt, pceltFetched); + + while (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) { + Moniker moniker = new Moniker(rgelt.getValue()); + + PointerByReference ppbc = new PointerByReference(); + Ole32.INSTANCE.CreateBindCtx(new DWORD(), ppbc); + //IBindCtx pbc = new BindCtx(ppbc.getValue()); + + BSTRByReference ppszDisplayName = new BSTRByReference(); + hr = moniker.GetDisplayName(ppbc.getValue(), moniker.getPointer(), ppszDisplayName); + COMUtils.checkRC(hr); + String name = ppszDisplayName.getString(); + Ole32.INSTANCE.CoTaskMemFree(ppszDisplayName.getPointer().getPointer(0)); + + PointerByReference ppunkObject = new PointerByReference(); + hr = rot.GetObject(moniker.getPointer(), ppunkObject); + COMUtils.checkRC(hr); + + IUnknown unk = new Unknown(ppunkObject.getValue()); + PointerByReference ppvObject = new PointerByReference(); + hr = unk.QueryInterface(new REFIID.ByValue(IUnknown.IID_IUNKNOWN), ppvObject); + assertEquals(0, hr.intValue()); + assertNotNull(ppvObject.getValue()); + + moniker.Release(); + + hr = iterator.Next(new ULONG(1), rgelt, pceltFetched); + } + + } + + @Test + public void NoteChangeTime() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + //Can't yet be tested as IMoniker is not fully implemented, + // so we can't register an object, and hence can't get a registration key + //rot.NoteChangeTime(dwRegister, pfiletime); + + } + + @Test + public void GetTimeOfLastChange() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + //Can't yet be tested as IMoniker is not fully implemented, + // so we can't register an object, and hence can't get a registration key + //rot.GetTimeOfLastChange(pmkObjectName, pfiletime); + + } + + @Test + public void EnumRunning() { + PointerByReference pprot = new PointerByReference(); + HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot); + COMUtils.checkRC(hr); + IRunningObjectTable rot = new RunningObjectTable(pprot.getValue()); + + PointerByReference ppenumMoniker = new PointerByReference(); + hr = rot.EnumRunning(ppenumMoniker); + COMUtils.checkRC(hr); + + assertNotNull(ppenumMoniker.getValue()); + + } + + + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ComEventCallbacks_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ComEventCallbacks_Test.java new file mode 100644 index 0000000000..cc099a13d1 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ComEventCallbacks_Test.java @@ -0,0 +1,268 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.platform.win32.User32; +import com.sun.jna.platform.win32.WinDef.HWND; +import com.sun.jna.platform.win32.COM.util.annotation.ComEventCallback; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; + +public class ComEventCallbacks_Test { + + Factory factory; + + @Before + public void before() { + this.factory = new Factory(); + } + + @After + public void after() { + this.factory.disposeAll(); + this.factory.getComThread().terminate(100); + } + + + @ComObject(progId="Word.Application") + interface ComIMsWordApp extends ComIApplication { + } + + @ComInterface(iid="{00020970-0000-0000-C000-000000000046}") + interface ComIApplication extends IUnknown, IConnectionPoint { + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComMethod + void Quit(boolean SaveChanges, Object OriginalFormat, Boolean RouteDocument); + + @ComProperty + ComIDocuments getDocuments(); + + } + + @ComInterface(iid="{0002096C-0000-0000-C000-000000000046}") + interface ComIDocuments { + @ComMethod + ComIDocument Open(String fileName); + @ComMethod + ComIDocument Add(); + } + + @ComInterface(iid="{0002096B-0000-0000-C000-000000000046}") + interface ComIDocument { + @ComProperty + String getFullName(); + + @ComMethod + void Select(); + } + + @ComInterface(iid="{00020962-0000-0000-C000-000000000046}") + interface ComIWindow {} + + @ComInterface(iid="{00020975-0000-0000-C000-000000000046}") + public interface ComISelection { + @ComProperty + String getText(); + } + + @ComInterface(iid="{00020A01-0000-0000-C000-000000000046}") + interface ApplicationEvents4_Event { + @ComEventCallback(dispid=10) + void WindowActivate(ComIDocument doc, ComIWindow win); + + @ComEventCallback(dispid=2) + void Quit(); + + @ComEventCallback(dispid=12) + void WindowSelectionChange(ComISelection sel); + } + + class ApplicationEvents4_EventListener extends AbstractComEventCallbackListener implements ApplicationEvents4_Event { + + @Override + public void errorReceivingCallbackEvent(String message, Exception exception) { + + } + + Boolean WindowActivate_called = null; + @Override + public void WindowActivate(ComIDocument doc, ComIWindow win) { + if (null!=doc && null !=win) { + String docName = doc.getFullName(); + WindowActivate_called = true; + } + } + + Boolean Quit_called = null; + @Override + public void Quit() { + Quit_called = true; + } + + Boolean WindowSelectionChange_called = null; + @Override + public void WindowSelectionChange(ComISelection sel) { + if (null!=sel) { + String t = sel.getText(); + WindowSelectionChange_called = true; + } + } + + } + + @Test + public void advise_Quit() { + // Create word object + ComIMsWordApp wordObj = factory.createObject(ComIMsWordApp.class); + ComIApplication wordApp = wordObj.queryInterface(ComIApplication.class); + wordApp.setVisible(true); + ApplicationEvents4_EventListener listener = new ApplicationEvents4_EventListener(); + wordApp.advise(ApplicationEvents4_Event.class, listener); + + wordApp.Quit(false, null, null); + + //Wait for event to happen + try { + Thread.sleep(200); + } catch (Exception e) { + e.printStackTrace(); + } + + Assert.assertNotNull(listener.Quit_called); + Assert.assertTrue(listener.Quit_called); + } + + @Test + public void unadvise_Quit() { + // Create word object + ComIMsWordApp wordObj = factory.createObject(ComIMsWordApp.class); + ComIApplication wordApp = wordObj.queryInterface(ComIApplication.class); + + ApplicationEvents4_EventListener listener = new ApplicationEvents4_EventListener(); + IComEventCallbackCookie cookie = wordApp.advise(ApplicationEvents4_Event.class, listener); + + wordApp.unadvise(ApplicationEvents4_Event.class, cookie); + listener.Quit_called=false; + wordApp.Quit(false, null, null); + + //Wait for event to happen + try { + Thread.sleep(200); + } catch (Exception e) { + e.printStackTrace(); + } + + Assert.assertNotNull(listener.Quit_called); + Assert.assertFalse(listener.Quit_called); + } + + @Test + public void WindowActivate() { + // Create word object + ComIMsWordApp wordObj = factory.createObject(ComIMsWordApp.class); + ComIApplication wordApp = wordObj.queryInterface(ComIApplication.class); + wordApp.setVisible(true); + ApplicationEvents4_EventListener listener = new ApplicationEvents4_EventListener(); + wordApp.advise(ApplicationEvents4_Event.class, listener); + wordApp.getDocuments().Add(); + + //bring word doc to front + HWND h = User32.INSTANCE.FindWindow("OpusApp", null); + if (h == null) + h = User32.INSTANCE.FindWindow("NetUIHWND", null); + User32.INSTANCE.ShowWindow(h, User32.SW_RESTORE); + User32.INSTANCE.SetForegroundWindow(h); + + //Wait for event to happen + try { + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } + + Assert.assertNotNull(listener.WindowActivate_called); + Assert.assertTrue(listener.WindowActivate_called); + + wordApp.Quit(false, null, null); + + } + + @Test + public void WindowSelectionChanged() { + // Create word object + ComIMsWordApp wordObj = factory.createObject(ComIMsWordApp.class); + ComIApplication wordApp = wordObj.queryInterface(ComIApplication.class); + wordApp.setVisible(true); + ApplicationEvents4_EventListener listener = new ApplicationEvents4_EventListener(); + wordApp.advise(ApplicationEvents4_Event.class, listener); + + ComIDocument doc = wordApp.getDocuments().Add(); + + doc.Select(); + + //Wait for event to happen + try { + Thread.sleep(200); + } catch (Exception e) { + e.printStackTrace(); + } + + Assert.assertNotNull(listener.WindowSelectionChange_called); + Assert.assertTrue(listener.WindowSelectionChange_called); + + wordApp.Quit(false, null, null); + + } + +// @Test +// public void WindowSelectionChanged_jvmCrash() { +// // Create word object +// ComIMsWordApp wordObj = factory.createObject(ComIMsWordApp.class); +// ComIApplication wordApp = wordObj.queryInterface(ComIApplication.class); +// wordApp.setVisible(true); +// ApplicationEvents4_EventListener listener = new ApplicationEvents4_EventListener(); +// wordApp.advise(ApplicationEvents4_Event.class, listener); +// +// +// +// ComIDocument doc = wordApp.getDocuments().Add(); +// +// doc.Select(); +// +// //Wait for event to happen +// try { +// Thread.sleep(2000000); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// Assert.assertNotNull(listener.WindowSelectionChange_called); +// Assert.assertTrue(listener.WindowSelectionChange_called); +// +// wordApp.Quit(false, null, null); +// +// } + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObject_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObject_Test.java new file mode 100644 index 0000000000..30a55dc892 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObject_Test.java @@ -0,0 +1,130 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import static org.junit.Assert.*; + +import java.util.List; + +import javax.management.InvalidApplicationException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.Ole32Util; +import com.sun.jna.platform.win32.OleAuto; +import com.sun.jna.platform.win32.Variant; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.ptr.PointerByReference; + +public class ProxyObject_Test { + + @ComInterface(iid="{00020970-0000-0000-C000-000000000046}") + interface Application extends IUnknown { + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComMethod + void Quit(boolean SaveChanges, Object OriginalFormat, Boolean RouteDocument); + } + + @ComObject(progId="Word.Application") + interface MsWordApp extends Application { + } + + Factory factory; + + @Before + public void before() { + this.factory = new Factory(); + //ensure there are no word applications running. + while(true) { + try { + MsWordApp ao = this.factory.fetchObject(MsWordApp.class); + Application a = ao.queryInterface(Application.class); + try { + a.Quit(true, null, null); + try { + //wait for it to quit + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace();e.getCause().printStackTrace(); + } + } catch(Exception e) { + break; + } + } + } + + @After + public void after() { + try { + //wait for it to quit + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + @Test + public void equals() { + MsWordApp comObj1 = this.factory.createObject(MsWordApp.class); + MsWordApp comObj2 = this.factory.fetchObject(MsWordApp.class); + + boolean res = comObj1.equals(comObj2); + + assertTrue(res); + + comObj1.Quit(false, null,null); + } + + @Test + public void notEquals() { + MsWordApp comObj1 = this.factory.createObject(MsWordApp.class); + MsWordApp comObj2 = this.factory.createObject(MsWordApp.class); + + boolean res = comObj1.equals(comObj2); + + assertFalse(res); + + comObj1.Quit(false, null,null); + } + + @Test + public void accessWhilstDisposing() { + MsWordApp comObj1 = this.factory.createObject(MsWordApp.class); + + //TODO: how to test this? + + this.factory.disposeAll(); + + } + +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/RunningObjectTable_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/RunningObjectTable_Test.java new file mode 100644 index 0000000000..544bec0365 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/RunningObjectTable_Test.java @@ -0,0 +1,133 @@ +/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package com.sun.jna.platform.win32.COM.util; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.sun.jna.platform.win32.COM.COMException; +import com.sun.jna.platform.win32.COM.COMUtils; +import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; +import com.sun.jna.platform.win32.COM.util.annotation.ComObject; +import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; +import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; +import com.sun.jna.platform.win32.Guid.IID; +import com.sun.jna.platform.win32.Ole32; +import com.sun.jna.platform.win32.Ole32Util; +import com.sun.jna.platform.win32.OleAuto; +import com.sun.jna.platform.win32.Variant; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.ptr.PointerByReference; + +public class RunningObjectTable_Test { + + @ComInterface(iid="{00020970-0000-0000-C000-000000000046}") + interface Application extends IUnknown { + @ComProperty + boolean getVisible(); + + @ComProperty + void setVisible(boolean value); + + @ComMethod + void Quit(boolean SaveChanges, Object OriginalFormat, Boolean RouteDocument); + } + + @ComObject(progId="Word.Application") + interface MsWordApp extends Application { + } + + Factory factory; + MsWordApp msWord; + + @Before + public void before() { + this.factory = new Factory(); + //ensure there is only one word application running. + while(true) { + try { + MsWordApp ao = this.factory.fetchObject(MsWordApp.class); + Application a = ao.queryInterface(Application.class); + try { + a.Quit(true, null, null); + try { + //wait for it to quit + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace();e.getCause().printStackTrace(); + } + } catch(Exception e) { + break; + } + } + + + this.msWord = this.factory.createObject(MsWordApp.class); + msWord.setVisible(true); + } + + @After + public void after() { + this.msWord.Quit(true, null, null); + try { + //wait for it to quit + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void getRunningObjectTable() { + IRunningObjectTable rot = this.factory.getRunningObjectTable(); + + assertNotNull(rot); + } + + @Test + public void enumRunning() { + IRunningObjectTable rot = this.factory.getRunningObjectTable(); + + for(IUnknown obj: rot.enumRunning()) { + try { + Application msw = obj.queryInterface(Application.class); + } catch(COMException ex) { + int i= 0; + } + } + } + + @Test + public void getActiveObjectsByInterface() { + IRunningObjectTable rot = this.factory.getRunningObjectTable(); + + List objs = rot.getActiveObjectsByInterface(Application.class); + assertTrue(objs.size() > 0); + + for(Application dobj: objs) { + msWord.setVisible(true); + boolean v2 = dobj.getVisible(); + assertEquals(true, v2); + } + + } +} diff --git a/contrib/platform/test/com/sun/jna/platform/win32/GuidTest.java b/contrib/platform/test/com/sun/jna/platform/win32/GuidTest.java index b5bb00b3b3..c474981348 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/GuidTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/GuidTest.java @@ -126,4 +126,18 @@ public void testNewGuid() { assertEquals(guidFromString.toGuidString(), guidString); } + + /** + * Tests the GUID.ByValue. + */ + public void testGuidByValue() { + GUID newGuid = GUID.newGuid(); + String guidString = newGuid.toGuidString(); + + GUID.ByValue bv = new GUID.ByValue(newGuid); + + String guidBV = bv.toGuidString(); + + assertEquals(guidBV, guidString); + } } diff --git a/maven/.project b/maven/.project new file mode 100644 index 0000000000..8396c70a8d --- /dev/null +++ b/maven/.project @@ -0,0 +1,17 @@ + + + com.sun.jna.parent + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/maven/.settings/org.eclipse.core.resources.prefs b/maven/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..4824b80263 --- /dev/null +++ b/maven/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/maven/.settings/org.eclipse.m2e.core.prefs b/maven/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..14b697b7bb --- /dev/null +++ b/maven/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/maven/com.sun.jna.core/.classpath b/maven/com.sun.jna.core/.classpath new file mode 100644 index 0000000000..94a4141d4f --- /dev/null +++ b/maven/com.sun.jna.core/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/maven/com.sun.jna.core/.gitignore b/maven/com.sun.jna.core/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/maven/com.sun.jna.core/.gitignore @@ -0,0 +1 @@ +/target diff --git a/maven/com.sun.jna.core/.project b/maven/com.sun.jna.core/.project new file mode 100644 index 0000000000..8dd6870f52 --- /dev/null +++ b/maven/com.sun.jna.core/.project @@ -0,0 +1,36 @@ + + + com.sun.jna.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + org.eclipse.m2e.core.maven2Nature + + + + src + 2 + $%7BPARENT-2-PROJECT_LOC%7D/src + + + test + 2 + $%7BPARENT-2-PROJECT_LOC%7D/test + + + diff --git a/maven/com.sun.jna.core/.settings/org.eclipse.core.resources.prefs b/maven/com.sun.jna.core/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..4824b80263 --- /dev/null +++ b/maven/com.sun.jna.core/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/maven/com.sun.jna.core/.settings/org.eclipse.jdt.core.prefs b/maven/com.sun.jna.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..54e493c07c --- /dev/null +++ b/maven/com.sun.jna.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/maven/com.sun.jna.core/.settings/org.eclipse.m2e.core.prefs b/maven/com.sun.jna.core/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..14b697b7bb --- /dev/null +++ b/maven/com.sun.jna.core/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/maven/com.sun.jna.core/.settings/org.eclipse.pde.core.prefs b/maven/com.sun.jna.core/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..394603ceee --- /dev/null +++ b/maven/com.sun.jna.core/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,2 @@ +BUNDLE_ROOT_PATH=target/classes +eclipse.preferences.version=1 diff --git a/maven/com.sun.jna.core/pom.xml b/maven/com.sun.jna.core/pom.xml new file mode 100644 index 0000000000..10e0c2ef50 --- /dev/null +++ b/maven/com.sun.jna.core/pom.xml @@ -0,0 +1,393 @@ + + 4.0.0 + + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + + com.sun.jna.core + + bundle + + + win32-x86-64 + ${project.basedir}/../com.sun.jna.native-repo/target/repo + com.sun.jna.native + com.sun.jna.native + ${parsedVersion.osgiVersion} + + + + + + org.reflections + reflections + 0.9.8 + test + + + + junit + junit + 4.11 + test + + + + + + + + project.local + project + file:${native-repo-dir} + + + + + ${project.basedir}/../../src + ${project.basedir}/../../test + + + + + ${project.build.outputDirectory} + + **/*.dll + **/*.a + **/*.so + **/*.jnilib + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + parse-version + + parse-version + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + unpack + process-resources + + unpack + + + ${native-repo-dir} + + + ${project.build.outputDirectory}/com/sun/jna/win32-x86 + jnidispatch.dll + win32-x86 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/win32-x86-64 + jnidispatch.dll + win32-x86-64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/w32ce-arm + jnidispatch.dll + w32ce-arm + ${native-groupId} + ${project.version} + jar + true + + + + ${project.build.outputDirectory}/com/sun/jna/sunos-x86 + libjnidispatch.so + sunos-x86 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/sunos-x86-64 + libjnidispatch.so + sunos-x86-64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/sunos-sparc + libjnidispatch.so + sunos-sparc + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/sunos-sparcv9 + libjnidispatch.so + sunos-sparcv9 + ${native-groupId} + ${project.version} + jar + true + + + + ${project.build.outputDirectory}/com/sun/jna/aix-ppc + libjnidispatch.a + aix-ppc + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/aix-ppc64 + libjnidispatch.a + aix-ppc64 + ${native-groupId} + ${project.version} + jar + true + + + + ${project.build.outputDirectory}/com/sun/jna/linux-ppc + libjnidispatch.so + linux-ppc + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-ppc64 + libjnidispatch.so + linux-ppc64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-x86 + libjnidispatch.so + linux-x86 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-x86-64 + libjnidispatch.so + linux-x86-64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-arm + libjnidispatch.so + linux-arm + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-aarch64 + libjnidispatch.so + linux-aarch64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/linux-ia64 + jnidispatch.dll + linux-ia64 + ${native-groupId} + ${project.version} + jar + true + + + + ${project.build.outputDirectory}/com/sun/jna/freebsd-x86 + libjnidispatch.so + freebsd-x86 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/freebsd-x86-64 + libjnidispatch.so + freebsd-x86-64 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/openbsd-x86 + libjnidispatch.so + openbsd-x86 + ${native-groupId} + ${project.version} + jar + true + + + ${project.build.outputDirectory}/com/sun/jna/openbsd-x86-64 + libjnidispatch.so + openbsd-x86-64 + ${native-groupId} + ${project.version} + jar + true + + + + ${project.build.outputDirectory}/com/sun/jna/darwin + libjnidispatch.jnilib + darwin + ${native-groupId} + ${project.version} + jar + true + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + 2.5.3 + true + + + 1.0 + 2 + ${project.artifactId} + ${project.artifactId} + ${bundle-version} + JNA Development Team + J2SE-1.4 + lazy + com.sun.jna,com.sun.jna.ptr,com.sun.jna.win32 + +com/sun/jna/win32-x86/jnidispatch.dll;processor=x86;osname=win32, +com/sun/jna/win32-x86-64/jnidispatch.dll;processor=x86-64;osname=win32, +com/sun/jna/w32ce-arm/jnidispatch.dll;processor=arm;osname=wince, + +com/sun/jna/sunos-x86/libjnidispatch.so;processor=x86;osname=sunos, +com/sun/jna/sunos-x86-64/libjnidispatch.so;processor=x86-64;osname=sunos, +com/sun/jna/sunos-sparc/libjnidispatch.so;processor=sparc;osname=sunos, +com/sun/jna/sunos-sparcv9/libjnidispatch.so;processor=sparcv9;osname=sunos, + +com/sun/jna/aix-ppc/libjnidispatch.a;processor=ppc;osname=aix, + +com/sun/jna/linux-x86/libjnidispatch.so;processor=x86;osname=linux, +com/sun/jna/linux-x86-64/libjnidispatch.so;processor=x86-64;osname=linux, +com/sun/jna/linux-arm/libjnidispatch.so;processor=arm;osname=linux, +com/sun/jna/linux-aarch64/libjnidispatch.so;processor=aarch64;osname=linux, + + +com/sun/jna/freebsd-x86/libjnidispatch.so;processor=x86;osname=freebsd, +com/sun/jna/freebsd-x86-64/libjnidispatch.so;processor=x86-64;osname=freebsd, +com/sun/jna/openbsd-x86/libjnidispatch.so;processor=x86;osname=openbsd, +com/sun/jna/openbsd-x86-64/libjnidispatch.so;processor=x86-64;osname=openbsd, + +com/sun/jna/darwin/libjnidispatch.jnilib;osname=macosx;processor=x86;processor=x86-64;processor=ppc + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + 1.6 + 1.6 + + + + + + + diff --git a/maven/com.sun.jna.feature/.classpath b/maven/com.sun.jna.feature/.classpath new file mode 100644 index 0000000000..019b3150a1 --- /dev/null +++ b/maven/com.sun.jna.feature/.classpath @@ -0,0 +1,4 @@ + + + + diff --git a/maven/com.sun.jna.feature/.gitignore b/maven/com.sun.jna.feature/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/maven/com.sun.jna.feature/.gitignore @@ -0,0 +1 @@ +/target diff --git a/maven/com.sun.jna.feature/.project b/maven/com.sun.jna.feature/.project new file mode 100644 index 0000000000..8272d1e365 --- /dev/null +++ b/maven/com.sun.jna.feature/.project @@ -0,0 +1,41 @@ + + + com.sun.jna.feature + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.FeatureBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.FeatureNature + + + + feature.xml + 1 + $%7BPROJECT_LOC%7D/src/main/resources/feature.xml + + + license.txt + 1 + $%7BPROJECT_LOC%7D/src/main/resources/license.txt + + + diff --git a/maven/com.sun.jna.feature/build.properties b/maven/com.sun.jna.feature/build.properties new file mode 100644 index 0000000000..cf058056a8 --- /dev/null +++ b/maven/com.sun.jna.feature/build.properties @@ -0,0 +1,2 @@ +bin.includes = feature.xml,\ + license.txt diff --git a/maven/com.sun.jna.feature/pom.xml b/maven/com.sun.jna.feature/pom.xml new file mode 100644 index 0000000000..3eb2982290 --- /dev/null +++ b/maven/com.sun.jna.feature/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + + com.sun.jna.feature + + jar + + + + + com.sun.jna + com.sun.jna.core + 4.1.1-SNAPSHOT + + + + com.sun.jna + com.sun.jna.platform + 4.1.1-SNAPSHOT + + + + + + + + + + + diff --git a/maven/com.sun.jna.feature/src/main/resources/feature.xml b/maven/com.sun.jna.feature/src/main/resources/feature.xml new file mode 100644 index 0000000000..1031aee04d --- /dev/null +++ b/maven/com.sun.jna.feature/src/main/resources/feature.xml @@ -0,0 +1,203 @@ + + + + + The JNA library encapsulated in an Eclipse plugin. + + + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + + + diff --git a/maven/com.sun.jna.feature/src/main/resources/license.txt b/maven/com.sun.jna.feature/src/main/resources/license.txt new file mode 100644 index 0000000000..ade750b16b --- /dev/null +++ b/maven/com.sun.jna.feature/src/main/resources/license.txt @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/maven/com.sun.jna.native-repo/.gitignore b/maven/com.sun.jna.native-repo/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/maven/com.sun.jna.native-repo/.gitignore @@ -0,0 +1 @@ +/target diff --git a/maven/com.sun.jna.native-repo/.project b/maven/com.sun.jna.native-repo/.project new file mode 100644 index 0000000000..6b05cd0b9d --- /dev/null +++ b/maven/com.sun.jna.native-repo/.project @@ -0,0 +1,17 @@ + + + com.sun.jna.native-repo + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/maven/com.sun.jna.native-repo/.settings/org.eclipse.m2e.core.prefs b/maven/com.sun.jna.native-repo/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..14b697b7bb --- /dev/null +++ b/maven/com.sun.jna.native-repo/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/maven/com.sun.jna.native-repo/pom.xml b/maven/com.sun.jna.native-repo/pom.xml new file mode 100644 index 0000000000..74f81d4425 --- /dev/null +++ b/maven/com.sun.jna.native-repo/pom.xml @@ -0,0 +1,333 @@ + + 4.0.0 + + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + + com.sun.jna.native-repo + + pom + + + com.sun.jna.native + com.sun.jna.native.test + ${project.basedir}/../../lib/native + ${project.basedir}/../../lib/test + ${project.build.directory}/repo + + + + + + + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + + + win32-x86 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/win32-x86.jar + ${native-groupId} + win32-x86 + ${project.version} + jar + + + + win32-x86-64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/win32-x86-64.jar + ${native-groupId} + win32-x86-64 + ${project.version} + jar + + + + w32ce-arm + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/w32ce-arm.jar + ${native-groupId} + w32ce-arm + ${project.version} + jar + + + + + sunos-x86 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/sunos-x86.jar + ${native-groupId} + sunos-x86 + ${project.version} + jar + + + + sunos-x86-64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/sunos-x86-64.jar + ${native-groupId} + sunos-x86-64 + ${project.version} + jar + + + + sunos-sparc + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/sunos-sparc.jar + ${native-groupId} + sunos-sparc + ${project.version} + jar + + + + sunos-sparcv9 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/sunos-sparcv9.jar + ${native-groupId} + sunos-sparcv9 + ${project.version} + jar + + + + + aix-ppc + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/aix-ppc.jar + ${native-groupId} + aix-ppc + ${project.version} + jar + + + + aix-ppc64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/aix-ppc64.jar + ${native-groupId} + aix-ppc64 + ${project.version} + jar + + + + + linux-ppc + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-ppc.jar + ${native-groupId} + linux-ppc + ${project.version} + jar + + + + linux-ppc64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-ppc64.jar + ${native-groupId} + linux-ppc64 + ${project.version} + jar + + + + linux-x86 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-x86.jar + ${native-groupId} + linux-x86 + ${project.version} + jar + + + + linux-x86-64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-x86-64.jar + ${native-groupId} + linux-x86-64 + ${project.version} + jar + + + + linux-arm + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-arm.jar + ${native-groupId} + linux-arm + ${project.version} + jar + + + + linux-aarch64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-aarch64.jar + ${native-groupId} + linux-aarch64 + ${project.version} + jar + + + + linux-ia64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/linux-ia64.jar + ${native-groupId} + linux-ia64 + ${project.version} + jar + + + + + freebsd-x86 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/freebsd-x86.jar + ${native-groupId} + freebsd-x86 + ${project.version} + jar + + + + freebsd-x86-64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/freebsd-x86-64.jar + ${native-groupId} + freebsd-x86-64 + ${project.version} + jar + + + + openbsd-x86 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/openbsd-x86.jar + ${native-groupId} + openbsd-x86 + ${project.version} + jar + + + + openbsd-x86-64 + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/openbsd-x86-64.jar + ${native-groupId} + openbsd-x86-64 + ${project.version} + jar + + + + + darwin + generate-resources + install-file + + ${native-repo-dir} + ${native-jars}/darwin.jar + ${native-groupId} + darwin + ${project.version} + jar + + + + + + + + + + diff --git a/maven/com.sun.jna.p2.repository/.gitignore b/maven/com.sun.jna.p2.repository/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/maven/com.sun.jna.p2.repository/.gitignore @@ -0,0 +1 @@ +/target diff --git a/maven/com.sun.jna.p2.repository/.project b/maven/com.sun.jna.p2.repository/.project new file mode 100644 index 0000000000..34f75d33b4 --- /dev/null +++ b/maven/com.sun.jna.p2.repository/.project @@ -0,0 +1,17 @@ + + + com.sun.jna.p2.repository + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/maven/com.sun.jna.p2.repository/.settings/org.eclipse.m2e.core.prefs b/maven/com.sun.jna.p2.repository/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..14b697b7bb --- /dev/null +++ b/maven/com.sun.jna.p2.repository/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/maven/com.sun.jna.p2.repository/pom.xml b/maven/com.sun.jna.p2.repository/pom.xml new file mode 100644 index 0000000000..7f7ff4d1e9 --- /dev/null +++ b/maven/com.sun.jna.p2.repository/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + + com.sun.jna.p2.repository + + pom + + + + + org.reficio + p2-maven-plugin + 1.1.2-SNAPSHOT + + + default-cli + package + + site + + + ${project.basedir}/src/main/resources/category.xml + + + com.sun.jna:com.sun.jna.core:${project.version} + false + true + + + com.sun.jna:com.sun.jna.platform:${project.version} + false + true + + + + + com.sun.jna:feature:${project.version} + false + + + + + + + + + diff --git a/maven/com.sun.jna.p2.repository/src/main/resources/category.xml b/maven/com.sun.jna.p2.repository/src/main/resources/category.xml new file mode 100644 index 0000000000..e7bbc82692 --- /dev/null +++ b/maven/com.sun.jna.p2.repository/src/main/resources/category.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/maven/com.sun.jna.platform/.classpath b/maven/com.sun.jna.platform/.classpath new file mode 100644 index 0000000000..b089109d64 --- /dev/null +++ b/maven/com.sun.jna.platform/.classpath @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven/com.sun.jna.platform/.gitignore b/maven/com.sun.jna.platform/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/maven/com.sun.jna.platform/.gitignore @@ -0,0 +1 @@ +/target diff --git a/maven/com.sun.jna.platform/.project b/maven/com.sun.jna.platform/.project new file mode 100644 index 0000000000..40f99139e2 --- /dev/null +++ b/maven/com.sun.jna.platform/.project @@ -0,0 +1,36 @@ + + + com.sun.jna.platform + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + src + 2 + $%7BPARENT-2-PROJECT_LOC%7D/contrib/platform/src + + + test + 2 + $%7BPARENT-2-PROJECT_LOC%7D/contrib/platform/test + + + diff --git a/maven/com.sun.jna.platform/.settings/org.eclipse.core.resources.prefs b/maven/com.sun.jna.platform/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..4824b80263 --- /dev/null +++ b/maven/com.sun.jna.platform/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/maven/com.sun.jna.platform/.settings/org.eclipse.jdt.core.prefs b/maven/com.sun.jna.platform/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..14f521d2ad --- /dev/null +++ b/maven/com.sun.jna.platform/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/maven/com.sun.jna.platform/.settings/org.eclipse.m2e.core.prefs b/maven/com.sun.jna.platform/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..14b697b7bb --- /dev/null +++ b/maven/com.sun.jna.platform/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/maven/com.sun.jna.platform/.settings/org.eclipse.pde.core.prefs b/maven/com.sun.jna.platform/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..394603ceee --- /dev/null +++ b/maven/com.sun.jna.platform/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,2 @@ +BUNDLE_ROOT_PATH=target/classes +eclipse.preferences.version=1 diff --git a/maven/com.sun.jna.platform/pom.xml b/maven/com.sun.jna.platform/pom.xml new file mode 100644 index 0000000000..c2a8515e48 --- /dev/null +++ b/maven/com.sun.jna.platform/pom.xml @@ -0,0 +1,119 @@ + + 4.0.0 + + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + + com.sun.jna.platform + + bundle + + + ${parsedVersion.osgiVersion} + + + + + + com.sun.jna + com.sun.jna.core + ${project.version} + + + + junit + junit + 4.11 + test + + + + + + + ${project.basedir}/../../contrib/platform/src + ${project.basedir}/../../contrib/platform/test + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + parse-version + + parse-version + + + + + + + + org.apache.felix + maven-bundle-plugin + 2.5.3 + true + + + 1.0 + 2 + ${project.artifactId} + ${project.artifactId} + ${bundle-version} + JNA Development Team + J2SE-1.4 + lazy + +com.sun.jna.platform, +com.sun.jna.platform.dnd, +com.sun.jna.platform.mac, +com.sun.jna.platform.unix, +com.sun.jna.platform.win32, +com.sun.jna.platform.win32.COM, +com.sun.jna.platform.win32.COM.tlb, +com.sun.jna.platform.win32.COM.tlb.imp, +com.sun.jna.platform.win32.COM.util, +com.sun.jna.platform.win32.COM.util.annotation, +com.sun.jna.platform.win32.COM.wince + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + 1.6 + 1.6 + + + + + + + diff --git a/maven/pom.xml b/maven/pom.xml new file mode 100644 index 0000000000..70bc83d247 --- /dev/null +++ b/maven/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.sun.jna + com.sun.jna.parent + 4.1.1-SNAPSHOT + + pom + + + + com.sun.jna.native-repo + + com.sun.jna.core + com.sun.jna.platform + com.sun.jna.feature + com.sun.jna.p2.repository + + + + + UTF-8 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.6 + 1.6 + + + + + + + + + + diff --git a/native/dispatch.c b/native/dispatch.c index faafd4d38f..7e3830cb67 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -2891,6 +2891,7 @@ static jboolean (JNICALL *pJAWT_GetAWT)(JNIEnv*,JAWT*); #endif /* NO_JAWT */ JNIEXPORT jlong JNICALL + //NOTE: must not have env parameter marked as UNUSED_ENV, as it is used on WIN32 build - #ifdef below. Java_com_sun_jna_Native_getWindowHandle0(JNIEnv* UNUSED_JAWT(env), jclass UNUSED(classp), jobject UNUSED_JAWT(w)) { jlong handle = 0; #ifndef NO_JAWT diff --git a/pom-jna-platform.xml b/pom-jna-platform.xml index 878fa63fb1..c5e12252c5 100644 --- a/pom-jna-platform.xml +++ b/pom-jna-platform.xml @@ -6,7 +6,7 @@ net.java.dev.jna jna-platform - 4.1.0 + 4.1.1-SNAPSHOT jar Java Native Access Platform @@ -46,7 +46,7 @@ net.java.dev.jna jna - 4.1.0 + 4.1.1-SNAPSHOT diff --git a/pom-jna.xml b/pom-jna.xml index 539400b6af..736e7b6241 100644 --- a/pom-jna.xml +++ b/pom-jna.xml @@ -6,7 +6,7 @@ net.java.dev.jna jna - 4.1.0 + 4.1.1-SNAPSHOT jar Java Native Access