use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class ComEventCallbacksObjectFactory_Test method testComEventCallback.
@Test
public void testComEventCallback() {
DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
CallbackProxy proxy = new CallbackProxy(factory, DWebBrowserEvents2.class, listener);
REFIID refiid = new REFIID(new IID(DWebBrowserEvents2.IID));
// precondition: the structures for the listenedToRiid and
// refiid have to be different (else the PointerType#equals would
// be enough
assertFalse(proxy.listenedToRiid.getPointer().equals(refiid.getPointer()));
// Neverthe less, the QueryInterface method has to return the
// correct pointer (the IID is relevant, not its wrapper
PointerByReference interfacePointer = new PointerByReference();
// Check the "business" interface
HRESULT hr = proxy.QueryInterface(refiid, interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// IUnknown must be implemented
hr = proxy.QueryInterface(new REFIID(IID_IUNKNOWN), interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// Currently only Dispatch based callbacks are supported,
// so this interface must be present to
hr = proxy.QueryInterface(new REFIID(IID_IDISPATCH), interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// Negative check -- this has to fail, the IID should not be
// assigned
hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
assertTrue(COMUtils.FAILED(hr));
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class Ole32Test method testCoInitializeEx.
public void testCoInitializeEx() {
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, 0);
assertTrue(W32Errors.SUCCEEDED(hr.intValue()) || hr.intValue() == W32Errors.RPC_E_CHANGED_MODE);
if (W32Errors.SUCCEEDED(hr.intValue()))
Ole32.INSTANCE.CoUninitialize();
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class Ole32Test method testCoCreateInstance.
public void testCoCreateInstance() {
HRESULT hrCI = Ole32.INSTANCE.CoInitializeEx(null, 0);
GUID guid = Ole32Util.getGUIDFromString(// Shell object
"{00021401-0000-0000-C000-000000000046}");
GUID riid = Ole32Util.getGUIDFromString(// IShellLinkA
"{000214EE-0000-0000-C000-000000000046}");
PointerByReference pDispatch = new PointerByReference();
HRESULT hr = // pOuter =
Ole32.INSTANCE.CoCreateInstance(// pOuter =
guid, // pOuter =
null, // aggregation
WTypes.CLSCTX_LOCAL_SERVER, riid, pDispatch);
assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
assertTrue(!pDispatch.equals(Pointer.NULL));
// here to wrap the native iUnknown pointer and call iUnknown.release()
if (W32Errors.SUCCEEDED(hrCI.intValue()))
Ole32.INSTANCE.CoUninitialize();
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class Shell32Test method testSHGetKnownFolderPath.
public void testSHGetKnownFolderPath() {
int flags = ShlObj.KNOWN_FOLDER_FLAG.NONE.getFlag();
PointerByReference outPath = new PointerByReference();
HANDLE token = null;
GUID guid = KnownFolders.FOLDERID_Fonts;
HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);
Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class RunningObjectTable_Test method Register.
@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);
}
Aggregations