use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class COMBindingBaseObject method init.
private void init(boolean useActiveInstance, GUID clsid, int dwClsContext) throws COMException {
HRESULT hr;
if (useActiveInstance) {
hr = OleAuto.INSTANCE.GetActiveObject(clsid, null, this.pUnknown);
if (COMUtils.SUCCEEDED(hr)) {
this.iUnknown = new Unknown(this.pUnknown.getValue());
hr = iUnknown.QueryInterface(new REFIID(IDispatch.IID_IDISPATCH), this.pDispatch);
} else {
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, IDispatch.IID_IDISPATCH, this.pDispatch);
}
} else {
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, IDispatch.IID_IDISPATCH, this.pDispatch);
}
COMUtils.checkRC(hr);
this.iDispatch = new Dispatch(this.pDispatch.getValue());
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class GuidTest method testBehaviourWithOle32.
/**
* Instantiates two guids, one with windows build-in function and one via
* jna and compares it.
*/
public void testBehaviourWithOle32() {
GUID ole32Guid = Ole32Util.getGUIDFromString("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
GUID jnaGuid = new GUID("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
assertEquals(ole32Guid, jnaGuid);
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class GuidTest method testGUIDFromString2.
/**
* Loads a GUID from string via the constructor and verify that the guid
* returned has the expected values in each byte.
*/
public void testGUIDFromString2() {
String sourceGuidStr = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}";
// test loading via constructor
GUID targetGuid = new GUID(sourceGuidStr);
assertEquals(targetGuid.toGuidString(), sourceGuidStr);
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class GuidTest method testGUIDFromBinary.
/**
* Loads a GUID from a byte array and verify that the guid returned has the
* expected values in each byte.
*/
public void testGUIDFromBinary() {
byte[] sourceGuidBArr = new byte[] { (byte) 0xA5, (byte) 0xDC, (byte) 0xBF, (byte) 0x10, (byte) 0x65, (byte) 0x30, (byte) 0x11, (byte) 0xD2, (byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0, (byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED };
// test loading via static method
GUID targetGuid = GUID.fromBinary(sourceGuidBArr);
byte[] targetGuidBArr = targetGuid.toByteArray();
for (int i = 0; i < sourceGuidBArr.length; i++) {
assertEquals(targetGuidBArr[i], sourceGuidBArr[i]);
}
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class ObjectFactory method fetchObject.
/**
* Gets and existing COM object (GetActiveObject) for the given progId and
* returns a ProxyObject for the given interface.
*/
public <T> T fetchObject(Class<T> comInterface) {
assert COMUtils.comIsInitialized() : "COM not initialized";
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 = 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;
}
Aggregations