more cleanup
Esse commit está contido em:
@@ -17,7 +17,6 @@ import com.sun.jna.platform.win32.WinReg;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class COMUtils.
|
||||
*/
|
||||
|
||||
@@ -30,75 +30,72 @@ import com.sun.jna.ptr.PointerByReference;
|
||||
*/
|
||||
public class IUnknown extends PointerType {
|
||||
|
||||
/**
|
||||
* The Class ByReference.
|
||||
*/
|
||||
public static class ByReference extends IUnknown implements
|
||||
Structure.ByReference {
|
||||
}
|
||||
/**
|
||||
* The Class ByReference.
|
||||
*/
|
||||
public static class ByReference extends IUnknown implements
|
||||
Structure.ByReference {
|
||||
}
|
||||
|
||||
/** The Constant IID_IDispatch. */
|
||||
public final static IID IID_IDispatch = new IID(
|
||||
"{00000000-0000-0000-C000-000000000046}");
|
||||
/** The Constant IID_IDispatch. */
|
||||
public final static IID IID_IDispatch = new IID(
|
||||
"{00000000-0000-0000-C000-000000000046}");
|
||||
|
||||
/**
|
||||
* Instantiates a new i unknown.
|
||||
*/
|
||||
public IUnknown() {
|
||||
}
|
||||
/**
|
||||
* Instantiates a new i unknown.
|
||||
*/
|
||||
public IUnknown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new i unknown.
|
||||
*
|
||||
* @param pvInstance
|
||||
* the pv instance
|
||||
*/
|
||||
public IUnknown(Pointer pvInstance) {
|
||||
this.setPointer(pvInstance);
|
||||
}
|
||||
/**
|
||||
* Instantiates a new i unknown.
|
||||
*
|
||||
* @param pvInstance
|
||||
* the pv instance
|
||||
*/
|
||||
public IUnknown(Pointer pvInstance) {
|
||||
super(pvInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query interface.
|
||||
*
|
||||
* @param riid
|
||||
* the riid
|
||||
* @param ppvObject
|
||||
* the ppv object
|
||||
* @return the hresult
|
||||
*/
|
||||
public HRESULT QueryInterface(IID riid, PointerByReference ppvObject) {
|
||||
Pointer base = this.getPointer();
|
||||
Pointer vptr = base.getPointer(0);
|
||||
System.out.println("vptr: " + vptr);
|
||||
Pointer root = vptr.getPointer(0);
|
||||
System.out.println("root: " + root);
|
||||
Function func = Function.getFunction(root);
|
||||
int hr = func.invokeInt(new Object[] { base, riid, ppvObject });
|
||||
System.out.println("returned: " + ppvObject.getValue());
|
||||
return new HRESULT(hr);
|
||||
}
|
||||
/**
|
||||
* Query interface.
|
||||
*
|
||||
* @param riid
|
||||
* the riid
|
||||
* @param ppvObject
|
||||
* the ppv object
|
||||
* @return the hresult
|
||||
*/
|
||||
public HRESULT QueryInterface(IID riid, PointerByReference ppvObject) {
|
||||
Pointer base = this.getPointer();
|
||||
Pointer vptr = base.getPointer(0);
|
||||
Pointer root = vptr.getPointer(0);
|
||||
Function func = Function.getFunction(root);
|
||||
int hr = func.invokeInt(new Object[] { base, riid, ppvObject });
|
||||
return new HRESULT(hr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the ref.
|
||||
*
|
||||
* @return the ulong
|
||||
*/
|
||||
public int AddRef() {
|
||||
Pointer vptr = this.getPointer().getPointer(0);
|
||||
Function func = Function.getFunction(vptr.getPointer(4));
|
||||
/**
|
||||
* Adds the ref.
|
||||
*
|
||||
* @return the ulong
|
||||
*/
|
||||
public int AddRef() {
|
||||
Pointer vptr = this.getPointer().getPointer(0);
|
||||
Function func = Function.getFunction(vptr.getPointer(4));
|
||||
|
||||
return func.invokeInt(new Object[] { this.getPointer() });
|
||||
}
|
||||
return func.invokeInt(new Object[] { this.getPointer() });
|
||||
}
|
||||
|
||||
/**
|
||||
* Release.
|
||||
*
|
||||
* @return the ulong
|
||||
*/
|
||||
public int Release() {
|
||||
Pointer vptr = this.getPointer().getPointer(0);
|
||||
Function func = Function.getFunction(vptr.getPointer(8));
|
||||
/**
|
||||
* Release.
|
||||
*
|
||||
* @return the ulong
|
||||
*/
|
||||
public int Release() {
|
||||
Pointer vptr = this.getPointer().getPointer(0);
|
||||
Function func = Function.getFunction(vptr.getPointer(8));
|
||||
|
||||
return func.invokeInt(new Object[] { this.getPointer() });
|
||||
}
|
||||
return func.invokeInt(new Object[] { this.getPointer() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,7 @@ public abstract class W32Errors implements WinError {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static final boolean SUCCEEDED(HRESULT hr) {
|
||||
if (hr != null)
|
||||
return SUCCEEDED(hr.intValue());
|
||||
else
|
||||
return false;
|
||||
return hr == null || SUCCEEDED(hr.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,10 +57,7 @@ public abstract class W32Errors implements WinError {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static final boolean FAILED(HRESULT hr) {
|
||||
if (hr != null)
|
||||
return FAILED(hr.intValue());
|
||||
else
|
||||
return false;
|
||||
return hr != null && FAILED(hr.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2012 Tobias Wolf, All Rights Reserved
|
||||
/* copyright (c) 2012 Tobias Wolf, 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
|
||||
@@ -31,45 +31,47 @@ public class IUnknownTest extends TestCase {
|
||||
private IDispatch iDispatch = new IDispatch();
|
||||
|
||||
private PointerByReference pDispatch = new PointerByReference();
|
||||
private boolean initialized;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// Initialize COM for this thread...
|
||||
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
|
||||
|
||||
if (W32Errors.FAILED(hr)) {
|
||||
this.tearDown();
|
||||
throw new COMException("CoInitializeEx() failed: " + Kernel32Util.formatMessage(hr));
|
||||
}
|
||||
assertTrue("CoInitializeEx() failed: "
|
||||
+ Kernel32Util.formatMessage(hr), W32Errors.SUCCEEDED(hr));
|
||||
initialized = true;
|
||||
|
||||
// Get CLSID for Word.Application...
|
||||
CLSID clsid = new CLSID();
|
||||
hr = Ole32.INSTANCE.CLSIDFromProgID("InternetExplorer.Application",
|
||||
clsid);
|
||||
|
||||
if (W32Errors.FAILED(hr)) {
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
throw new COMException("CLSIDFromProgID() failed: " + Kernel32Util.formatMessage(hr));
|
||||
}
|
||||
assertTrue("CLSIDFromProgID() failed: "
|
||||
+ Kernel32Util.formatMessage(hr), W32Errors.SUCCEEDED(hr));
|
||||
|
||||
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null,
|
||||
WTypes.CLSCTX_LOCAL_SERVER, IDispatch.IID_IDispatch,
|
||||
WTypes.CLSCTX_LOCAL_SERVER,
|
||||
IDispatch.IID_IDispatch,
|
||||
this.pDispatch);
|
||||
|
||||
if (W32Errors.FAILED(hr)) {
|
||||
throw new COMException("Internet Explorer not registered properly");
|
||||
}
|
||||
assertTrue("Internet Explorer not registered properly: "
|
||||
+ Kernel32Util.formatMessage(hr), W32Errors.SUCCEEDED(hr));
|
||||
|
||||
this.iDispatch = new IDispatch(pDispatch.getPointer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (initialized) {
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
}
|
||||
}
|
||||
|
||||
public void testQueryInterface() {
|
||||
PointerByReference ppvObject = new PointerByReference();
|
||||
this.iDispatch.QueryInterface(IDispatch.IID_IDispatch, ppvObject);
|
||||
assertNotNull(ppvObject.getValue());
|
||||
System.out.println("ppvObject:" + ppvObject.toString());
|
||||
}
|
||||
|
||||
public void testAddRef() {
|
||||
@@ -82,12 +84,6 @@ public class IUnknownTest extends TestCase {
|
||||
assertEquals("Wrong release result", 0, release);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(IUnknownTest.class);
|
||||
}
|
||||
|
||||
@@ -45,223 +45,223 @@ import com.sun.jna.ptr.PointerByReference;
|
||||
*/
|
||||
public class ITypeInfoTest extends TestCase {
|
||||
|
||||
private COMObject comObj = null;
|
||||
private COMObject comObj = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(ITypeInfoTest.class);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(ITypeInfoTest.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
if (this.comObj == null) {
|
||||
// create a shell COM object
|
||||
this.comObj = new COMObject("Shell.Application", false);
|
||||
}
|
||||
}
|
||||
if (this.comObj == null) {
|
||||
// create a shell COM object
|
||||
this.comObj = new COMObject("Shell.Application", false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (this.comObj != null) {
|
||||
this.comObj.release();
|
||||
}
|
||||
}
|
||||
if (this.comObj != null) {
|
||||
this.comObj.release();
|
||||
}
|
||||
}
|
||||
|
||||
public ITypeInfo getTypeInfo() {
|
||||
// get user default lcid
|
||||
LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
|
||||
// create a IUnknown pointer
|
||||
PointerByReference ppTInfo = new PointerByReference();
|
||||
public ITypeInfo getTypeInfo() {
|
||||
// get user default lcid
|
||||
LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
|
||||
// create a IUnknown pointer
|
||||
PointerByReference ppTInfo = new PointerByReference();
|
||||
|
||||
comObj.getIDispatch().GetTypeInfo(new UINT(0), lcid, ppTInfo);
|
||||
comObj.getIDispatch().GetTypeInfo(new UINT(0), lcid, ppTInfo);
|
||||
|
||||
return new ITypeInfo(ppTInfo.getValue());
|
||||
}
|
||||
return new ITypeInfo(ppTInfo.getValue());
|
||||
}
|
||||
|
||||
public void testGetTypeAttr() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
TYPEATTR.ByReference pTypeAttr = new TYPEATTR.ByReference();
|
||||
HRESULT hr = typeInfo.GetTypeAttr(pTypeAttr);
|
||||
public void testGetTypeAttr() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
TYPEATTR.ByReference pTypeAttr = new TYPEATTR.ByReference();
|
||||
HRESULT hr = typeInfo.GetTypeAttr(pTypeAttr);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetTypeAttr: " + pTypeAttr.toString(true));
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetTypeAttr: " + pTypeAttr.toString(true));
|
||||
}
|
||||
|
||||
public void testGetTypeComp() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
ITypeComp.ByReference pTComp = new ITypeComp.ByReference();
|
||||
HRESULT hr = typeInfo.GetTypeComp(pTComp);
|
||||
public void testGetTypeComp() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
ITypeComp.ByReference pTComp = new ITypeComp.ByReference();
|
||||
HRESULT hr = typeInfo.GetTypeComp(pTComp);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetTypeComp: " + pTComp.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetTypeComp: " + pTComp.toString());
|
||||
}
|
||||
|
||||
public void testGetFuncDesc() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
FUNCDESC.ByReference pFuncDesc = new FUNCDESC.ByReference();
|
||||
HRESULT hr = typeInfo.GetFuncDesc(new UINT(1), pFuncDesc);
|
||||
public void testGetFuncDesc() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
FUNCDESC.ByReference pFuncDesc = new FUNCDESC.ByReference();
|
||||
HRESULT hr = typeInfo.GetFuncDesc(new UINT(1), pFuncDesc);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetFuncDesc: " + pFuncDesc.toString(true));
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetFuncDesc: " + pFuncDesc.toString(true));
|
||||
}
|
||||
|
||||
public void testGetVarDesc() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
VARDESC.ByReference pVarDesc = new VARDESC.ByReference();
|
||||
HRESULT hr = typeInfo.GetVarDesc(new UINT(0), pVarDesc);
|
||||
public void testGetVarDesc() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
VARDESC.ByReference pVarDesc = new VARDESC.ByReference();
|
||||
HRESULT hr = typeInfo.GetVarDesc(new UINT(0), pVarDesc);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetVarDesc: " + pVarDesc.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetVarDesc: " + pVarDesc.toString());
|
||||
}
|
||||
|
||||
public void testGetNames() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(1);
|
||||
BSTR[] rgBstrNames = new BSTR[1];
|
||||
UINT cMaxNames = new UINT(1);
|
||||
UINTByReference pcNames = new UINTByReference();
|
||||
HRESULT hr = typeInfo.GetNames(memid, rgBstrNames, cMaxNames, pcNames);
|
||||
public void testGetNames() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(1);
|
||||
BSTR[] rgBstrNames = new BSTR[1];
|
||||
UINT cMaxNames = new UINT(1);
|
||||
UINTByReference pcNames = new UINTByReference();
|
||||
HRESULT hr = typeInfo.GetNames(memid, rgBstrNames, cMaxNames, pcNames);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("rgBstrNames: " + rgBstrNames[0].getValue());
|
||||
System.out.println("pcNames: " + pcNames.getValue().intValue());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("rgBstrNames: " + rgBstrNames[0].getValue());
|
||||
System.out.println("pcNames: " + pcNames.getValue().intValue());
|
||||
}
|
||||
|
||||
public void testGetRefTypeOfImplType() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
HREFTYPEByReference pRefType = new HREFTYPEByReference();
|
||||
HRESULT hr = typeInfo.GetRefTypeOfImplType(new UINT(0), pRefType);
|
||||
public void testGetRefTypeOfImplType() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
HREFTYPEByReference pRefType = new HREFTYPEByReference();
|
||||
HRESULT hr = typeInfo.GetRefTypeOfImplType(new UINT(0), pRefType);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetRefTypeOfImplType: " + pRefType.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetRefTypeOfImplType: " + pRefType.toString());
|
||||
}
|
||||
|
||||
public void testGetImplTypeFlags() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
IntByReference pImplTypeFlags = new IntByReference();
|
||||
HRESULT hr = typeInfo.GetImplTypeFlags(new UINT(0), pImplTypeFlags);
|
||||
public void testGetImplTypeFlags() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
IntByReference pImplTypeFlags = new IntByReference();
|
||||
HRESULT hr = typeInfo.GetImplTypeFlags(new UINT(0), pImplTypeFlags);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetImplTypeFlags: " + pImplTypeFlags.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetImplTypeFlags: " + pImplTypeFlags.toString());
|
||||
}
|
||||
|
||||
public void testGetIDsOfNames() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
WString[] rgszNames = { new WString("Visible") };
|
||||
UINT cNames = new UINT(1);
|
||||
MEMBERID[] pMemId = new MEMBERID[1];
|
||||
HRESULT hr = typeInfo.GetIDsOfNames(rgszNames, cNames, pMemId);
|
||||
public void testGetIDsOfNames() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
WString[] rgszNames = { new WString("Visible") };
|
||||
UINT cNames = new UINT(1);
|
||||
MEMBERID[] pMemId = new MEMBERID[1];
|
||||
HRESULT hr = typeInfo.GetIDsOfNames(rgszNames, cNames, pMemId);
|
||||
|
||||
COMUtils.checkAutoRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pMemId: " + pMemId.toString());
|
||||
}
|
||||
COMUtils.checkAutoRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pMemId: " + pMemId.toString());
|
||||
}
|
||||
|
||||
public void testInvoke() {
|
||||
fail("not implemented due complexity.");
|
||||
}
|
||||
public void testInvoke() {
|
||||
fail("Test not implemented");
|
||||
}
|
||||
|
||||
public void testGetDocumentation() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrName = new BSTR();
|
||||
BSTR pBstrDocString = new BSTR();
|
||||
DWORDByReference pdwHelpContext = new DWORDByReference();
|
||||
BSTR pBstrHelpFile = new BSTR();
|
||||
HRESULT hr = typeInfo.GetDocumentation(memid, pBstrName,
|
||||
pBstrDocString, pdwHelpContext, pBstrHelpFile);
|
||||
public void testGetDocumentation() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrName = new BSTR();
|
||||
BSTR pBstrDocString = new BSTR();
|
||||
DWORDByReference pdwHelpContext = new DWORDByReference();
|
||||
BSTR pBstrHelpFile = new BSTR();
|
||||
HRESULT hr = typeInfo.GetDocumentation(memid, pBstrName,
|
||||
pBstrDocString, pdwHelpContext, pBstrHelpFile);
|
||||
|
||||
COMUtils.checkAutoRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("memid: " + memid.intValue());
|
||||
System.out.println("pBstrName: " + pBstrName.getValue());
|
||||
System.out.println("pBstrDocString: " + pBstrDocString.getValue());
|
||||
System.out.println("pdwHelpContext: " + pdwHelpContext.getValue());
|
||||
System.out.println("pBstrHelpFile: " + pBstrHelpFile.getValue());
|
||||
}
|
||||
COMUtils.checkAutoRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("memid: " + memid.intValue());
|
||||
System.out.println("pBstrName: " + pBstrName.getValue());
|
||||
System.out.println("pBstrDocString: " + pBstrDocString.getValue());
|
||||
System.out.println("pdwHelpContext: " + pdwHelpContext.getValue());
|
||||
System.out.println("pBstrHelpFile: " + pBstrHelpFile.getValue());
|
||||
}
|
||||
|
||||
public void testGetDllEntry() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrDllName = new BSTR();
|
||||
BSTR pBstrName = new BSTR();
|
||||
WORDByReference pwOrdinal = new WORDByReference();
|
||||
HRESULT hr = typeInfo.GetDllEntry(memid, INVOKEKIND.INVOKE_FUNC,
|
||||
pBstrDllName, pBstrName, pwOrdinal);
|
||||
public void testGetDllEntry() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrDllName = new BSTR();
|
||||
BSTR pBstrName = new BSTR();
|
||||
WORDByReference pwOrdinal = new WORDByReference();
|
||||
HRESULT hr = typeInfo.GetDllEntry(memid, INVOKEKIND.INVOKE_FUNC,
|
||||
pBstrDllName, pBstrName, pwOrdinal);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("memid: " + memid.intValue());
|
||||
System.out.println("pBstrDllName: " + pBstrDllName.getValue());
|
||||
System.out.println("pBstrName: " + pBstrName.getValue());
|
||||
System.out.println("pwOrdinal: " + pwOrdinal.getValue());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("memid: " + memid.intValue());
|
||||
System.out.println("pBstrDllName: " + pBstrDllName.getValue());
|
||||
System.out.println("pBstrName: " + pBstrName.getValue());
|
||||
System.out.println("pwOrdinal: " + pwOrdinal.getValue());
|
||||
}
|
||||
|
||||
public void testGetRefTypeInfo() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
HREFTYPE hRefType = new HREFTYPE();
|
||||
ITypeInfo.ByReference ppTInfo = new ITypeInfo.ByReference();
|
||||
HRESULT hr = typeInfo.GetRefTypeInfo(hRefType, ppTInfo);
|
||||
public void testGetRefTypeInfo() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
HREFTYPE hRefType = new HREFTYPE();
|
||||
ITypeInfo.ByReference ppTInfo = new ITypeInfo.ByReference();
|
||||
HRESULT hr = typeInfo.GetRefTypeInfo(hRefType, ppTInfo);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetRefTypeInfo: " + ppTInfo.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("GetRefTypeInfo: " + ppTInfo.toString());
|
||||
}
|
||||
|
||||
public void testAddressOfMember() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID();
|
||||
PointerByReference ppv = new PointerByReference();
|
||||
HRESULT hr = typeInfo.AddressOfMember(memid, INVOKEKIND.INVOKE_FUNC,
|
||||
ppv);
|
||||
public void testAddressOfMember() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID();
|
||||
PointerByReference ppv = new PointerByReference();
|
||||
HRESULT hr = typeInfo.AddressOfMember(memid, INVOKEKIND.INVOKE_FUNC,
|
||||
ppv);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("AddressOfMember: " + ppv.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("AddressOfMember: " + ppv.toString());
|
||||
}
|
||||
|
||||
public void testCreateInstance() {
|
||||
fail("not implemented due complexity.");
|
||||
}
|
||||
public void testCreateInstance() {
|
||||
fail("Test not implemented");
|
||||
}
|
||||
|
||||
public void testGetMops() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrMops = new BSTR();
|
||||
HRESULT hr = typeInfo.GetMops(memid, pBstrMops);
|
||||
public void testGetMops() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
MEMBERID memid = new MEMBERID(0);
|
||||
BSTR pBstrMops = new BSTR();
|
||||
HRESULT hr = typeInfo.GetMops(memid, pBstrMops);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pBstrMops: " + pBstrMops.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pBstrMops: " + pBstrMops.toString());
|
||||
}
|
||||
|
||||
public void testGetContainingTypeLib() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
ITypeLib.ByReference pTLib = new ITypeLib.ByReference();
|
||||
UINTByReference pIndex = new UINTByReference();
|
||||
HRESULT hr = typeInfo.GetContainingTypeLib(pTLib, pIndex);
|
||||
public void testGetContainingTypeLib() {
|
||||
ITypeInfo typeInfo = getTypeInfo();
|
||||
ITypeLib.ByReference pTLib = new ITypeLib.ByReference();
|
||||
UINTByReference pIndex = new UINTByReference();
|
||||
HRESULT hr = typeInfo.GetContainingTypeLib(pTLib, pIndex);
|
||||
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pTLib: " + pTLib.toString());
|
||||
System.out.println("pTLib: " + pIndex.toString());
|
||||
}
|
||||
COMUtils.checkTypeLibRC(hr);
|
||||
assertEquals(0, hr.intValue());
|
||||
System.out.println("pTLib: " + pTLib.toString());
|
||||
System.out.println("pTLib: " + pIndex.toString());
|
||||
}
|
||||
|
||||
public void testReleaseTypeAttr() {
|
||||
fail("not implemented due complexity.");
|
||||
}
|
||||
public void testReleaseTypeAttr() {
|
||||
fail("Test not implemented");
|
||||
}
|
||||
|
||||
public void testReleaseFuncDesc() {
|
||||
fail("not implemented due complexity.");
|
||||
}
|
||||
public void testReleaseFuncDesc() {
|
||||
fail("Test not implemented");
|
||||
}
|
||||
|
||||
public void testReleaseVarDesc() {
|
||||
fail("not implemented due complexity.");
|
||||
}
|
||||
public void testReleaseVarDesc() {
|
||||
fail("Test not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import junit.framework.TestCase;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.Guid.CLSID;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
@@ -26,85 +27,106 @@ import com.sun.jna.ptr.PointerByReference;
|
||||
*/
|
||||
public class Ole32Test extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Ole32Test.class);
|
||||
}
|
||||
private boolean initialized;
|
||||
|
||||
public void testCoCreateGUID() {
|
||||
GUID pguid = new GUID();
|
||||
assertEquals(W32Errors.S_OK, Ole32.INSTANCE.CoCreateGuid(pguid));
|
||||
assertTrue(pguid.Data1 != 0 || pguid.Data2 != 0 || pguid.Data3 != 0
|
||||
&& pguid.Data4 != null);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Ole32Test.class);
|
||||
}
|
||||
|
||||
public void testIIDFromString() {
|
||||
GUID lpiid = new GUID();
|
||||
assertEquals(W32Errors.S_OK, Ole32.INSTANCE.IIDFromString(
|
||||
"{13709620-C279-11CE-A49E-444553540000}", lpiid)); // Shell.Application.1
|
||||
assertEquals(0x13709620, lpiid.Data1);
|
||||
assertEquals(0xFFFFC279, lpiid.Data2);
|
||||
assertEquals(0x11CE, lpiid.Data3);
|
||||
assertEquals(0xFFFFFFA4, lpiid.Data4[0]);
|
||||
assertEquals(0xFFFFFF9E, lpiid.Data4[1]);
|
||||
assertEquals(0x44, lpiid.Data4[2]);
|
||||
assertEquals(0x45, lpiid.Data4[3]);
|
||||
assertEquals(0x53, lpiid.Data4[4]);
|
||||
assertEquals(0x54, lpiid.Data4[5]);
|
||||
assertEquals(0, lpiid.Data4[6]);
|
||||
assertEquals(0, lpiid.Data4[7]);
|
||||
}
|
||||
protected void tearDown() {
|
||||
if (initialized) {
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
}
|
||||
}
|
||||
|
||||
public void testStringFromGUID2() {
|
||||
GUID pguid = new GUID();
|
||||
pguid.Data1 = 0;
|
||||
pguid.Data2 = 0;
|
||||
pguid.Data3 = 0;
|
||||
for (int i = 0; i < pguid.Data4.length; i++) {
|
||||
pguid.Data4[i] = 0;
|
||||
}
|
||||
int max = 39;
|
||||
char[] lpsz = new char[max];
|
||||
int len = Ole32.INSTANCE.StringFromGUID2(pguid, lpsz, max);
|
||||
assertTrue(len > 1);
|
||||
lpsz[len - 1] = 0;
|
||||
assertEquals("{00000000-0000-0000-0000-000000000000}",
|
||||
Native.toString(lpsz));
|
||||
}
|
||||
public void testCoCreateGUID() {
|
||||
GUID pguid = new GUID();
|
||||
assertEquals(W32Errors.S_OK, Ole32.INSTANCE.CoCreateGuid(pguid));
|
||||
assertTrue(pguid.Data1 != 0 || pguid.Data2 != 0 || pguid.Data3 != 0
|
||||
&& pguid.Data4 != null);
|
||||
}
|
||||
|
||||
public void testCoInitializeEx() {
|
||||
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
|
||||
assertTrue(W32Errors.SUCCEEDED(hr.intValue())
|
||||
|| hr.intValue() == W32Errors.RPC_E_CHANGED_MODE);
|
||||
if (W32Errors.SUCCEEDED(hr.intValue()))
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
}
|
||||
public void testIIDFromString() {
|
||||
GUID lpiid = new GUID();
|
||||
// Shell.Application.1
|
||||
assertEquals(W32Errors.S_OK, Ole32.INSTANCE.IIDFromString("{13709620-C279-11CE-A49E-444553540000}", lpiid));
|
||||
assertEquals(0x13709620, lpiid.Data1);
|
||||
assertEquals(0xFFFFC279, lpiid.Data2);
|
||||
assertEquals(0x11CE, lpiid.Data3);
|
||||
assertEquals(0xFFFFFFA4, lpiid.Data4[0]);
|
||||
assertEquals(0xFFFFFF9E, lpiid.Data4[1]);
|
||||
assertEquals(0x44, lpiid.Data4[2]);
|
||||
assertEquals(0x45, lpiid.Data4[3]);
|
||||
assertEquals(0x53, lpiid.Data4[4]);
|
||||
assertEquals(0x54, lpiid.Data4[5]);
|
||||
assertEquals(0, lpiid.Data4[6]);
|
||||
assertEquals(0, lpiid.Data4[7]);
|
||||
}
|
||||
|
||||
public void testCoCreateInstance() {
|
||||
HRESULT hrCI = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
|
||||
public void testStringFromGUID2() {
|
||||
GUID pguid = new GUID();
|
||||
pguid.Data1 = 0;
|
||||
pguid.Data2 = 0;
|
||||
pguid.Data3 = 0;
|
||||
for (int i = 0; i < pguid.Data4.length; i++) {
|
||||
pguid.Data4[i] = 0;
|
||||
}
|
||||
int max = 39;
|
||||
char[] lpsz = new char[max];
|
||||
int len = Ole32.INSTANCE.StringFromGUID2(pguid, lpsz, max);
|
||||
assertTrue(len > 1);
|
||||
lpsz[len - 1] = 0;
|
||||
assertEquals("{00000000-0000-0000-0000-000000000000}",
|
||||
Native.toString(lpsz));
|
||||
}
|
||||
|
||||
GUID guid = Ole32Util
|
||||
.getGUIDFromString("{13709620-C279-11CE-A49E-444553540000}"); // Shell
|
||||
// object
|
||||
GUID riid = Ole32Util
|
||||
.getGUIDFromString("{D8F015C0-C278-11CE-A49E-444553540000}"); // IShellDispatch
|
||||
public void testCoInitializeEx() {
|
||||
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
|
||||
assertTrue(W32Errors.SUCCEEDED(hr)
|
||||
|| hr.intValue() == W32Errors.RPC_E_CHANGED_MODE);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
PointerByReference pDispatch = new PointerByReference();
|
||||
public void testCoCreateInstance() {
|
||||
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
|
||||
|
||||
HRESULT hr = Ole32.INSTANCE.CoCreateInstance(guid, null, // pOuter =
|
||||
// null, no
|
||||
// aggregation
|
||||
WTypes.CLSCTX_LOCAL_SERVER, riid, pDispatch);
|
||||
assertTrue(Kernel32Util.formatMessage(hr), W32Errors.SUCCEEDED(hr.intValue()));
|
||||
assertNotNull("Returned dispatch pointer should be non-null", pDispatch.getValue());
|
||||
// We leak this iUnknown reference because we don't have the JNACOM lib
|
||||
// here to wrap the native iUnknown pointer and call iUnknown.release()
|
||||
if (W32Errors.SUCCEEDED(hrCI.intValue()))
|
||||
Ole32.INSTANCE.CoUninitialize();
|
||||
}
|
||||
assertTrue("CoInitializeEx failed: "
|
||||
+ Kernel32Util.formatMessage(hr),
|
||||
W32Errors.SUCCEEDED(hr));
|
||||
initialized = true;
|
||||
|
||||
public final void testCLSIDFromProgID() {
|
||||
final Guid.CLSID clsid = new Guid.CLSID();
|
||||
assertEquals(WinError.S_OK, Ole32.INSTANCE.CLSIDFromProgID("jpegfile", clsid));
|
||||
assertEquals("{25336920-03F9-11CF-8FD0-00AA00686F13}", clsid.toGuidString());
|
||||
}
|
||||
final String NAME = "Shell.Application";
|
||||
CLSID clsid = new CLSID();
|
||||
hr = Ole32.INSTANCE.CLSIDFromProgID(NAME, clsid);
|
||||
assertTrue("CLSIDFromProgID(" + NAME + ") failed: "
|
||||
+ Kernel32Util.formatMessage(hr),
|
||||
W32Errors.SUCCEEDED(hr));
|
||||
|
||||
final String IID_IShellDispatch = "{D8F015C0-C278-11CE-A49E-444553540000}";
|
||||
//GUID clsid = Ole32Util.getGUIDFromString(CLSID_Shell);
|
||||
GUID iid = Ole32Util.getGUIDFromString(IID_IShellDispatch);
|
||||
|
||||
PointerByReference pDispatch = new PointerByReference();
|
||||
|
||||
hr = Ole32.INSTANCE
|
||||
.CoCreateInstance(clsid, null, // pOuter =
|
||||
// null, no
|
||||
// aggregation
|
||||
WTypes.CLSCTX_LOCAL_SERVER,
|
||||
iid, pDispatch);
|
||||
assertTrue("Error looking up Shell/IShellDispatch: "
|
||||
+ Kernel32Util.formatMessage(hr),
|
||||
W32Errors.SUCCEEDED(hr));
|
||||
assertNotNull("Returned dispatch pointer should be non-null",
|
||||
pDispatch.getValue());
|
||||
// We leak this iUnknown reference because we don't have the
|
||||
// JNA COM lib here to wrap the native iUnknown pointer and
|
||||
// call iUnknown.release()
|
||||
}
|
||||
|
||||
public final void testCLSIDFromProgID() {
|
||||
final Guid.CLSID clsid = new Guid.CLSID();
|
||||
assertEquals(WinError.S_OK, Ole32.INSTANCE.CLSIDFromProgID("jpegfile", clsid));
|
||||
assertEquals("{25336920-03F9-11CF-8FD0-00AA00686F13}", clsid.toGuidString());
|
||||
}
|
||||
}
|
||||
|
||||
Arquivo binário não exibido.
Referência em uma Nova Issue
Bloquear um usuário