use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class ProxyObject method queryInterface.
@Override
public <T> T queryInterface(Class<T> comInterface) throws COMException {
assert COMUtils.comIsInitialized() : "COM not initialized";
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 = ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(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);
}
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class Crypt32Util method cryptUnprotectData.
/**
* Unprotect a blob of data.
* @param data
* Data to unprotect.
* @param entropy
* Optional entropy.
* @param flags
* Optional flags.
* @param prompt
* Optional prompt structure.
* @return
* Unprotected blob of data.
*/
public static byte[] cryptUnprotectData(byte[] data, byte[] entropy, int flags, CRYPTPROTECT_PROMPTSTRUCT prompt) {
DATA_BLOB pDataIn = new DATA_BLOB(data);
DATA_BLOB pDataUnprotected = new DATA_BLOB();
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
PointerByReference pDescription = new PointerByReference();
Win32Exception err = null;
byte[] unProtectedData = null;
try {
if (!Crypt32.INSTANCE.CryptUnprotectData(pDataIn, pDescription, pEntropy, null, prompt, flags, pDataUnprotected)) {
err = new Win32Exception(Kernel32.INSTANCE.GetLastError());
} else {
unProtectedData = pDataUnprotected.getData();
}
} finally {
if (pDataUnprotected.pbData != null) {
try {
Kernel32Util.freeLocalMemory(pDataUnprotected.pbData);
} catch (Win32Exception e) {
if (err == null) {
err = e;
} else {
err.addSuppressed(e);
}
}
}
if (pDescription.getValue() != null) {
try {
Kernel32Util.freeLocalMemory(pDescription.getValue());
} catch (Win32Exception e) {
if (err == null) {
err = e;
} else {
err.addSuppressed(e);
}
}
}
}
if (err != null) {
throw err;
}
return unProtectedData;
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class TypeInfoUtil method CreateInstance.
/**
* Creates the instance.
*
* @param pUnkOuter
* the unk outer
* @param riid
* the riid
* @return the pointer by reference
*/
public PointerByReference CreateInstance(IUnknown pUnkOuter, REFIID riid) {
PointerByReference ppvObj = new PointerByReference();
HRESULT hr = this.typeInfo.CreateInstance(pUnkOuter, riid, ppvObj);
COMUtils.checkRC(hr);
return ppvObj;
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class TypeInfoUtil method getTypeAttr.
/**
* Gets the type attr.
*
* @return the type attr
*/
public TYPEATTR getTypeAttr() {
PointerByReference ppTypeAttr = new PointerByReference();
HRESULT hr = this.typeInfo.GetTypeAttr(ppTypeAttr);
COMUtils.checkRC(hr);
return new TYPEATTR(ppTypeAttr.getValue());
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class TypeInfoUtil method getVarDesc.
/**
* Gets the var desc.
*
* @param index
* the index
* @return the var desc
*/
public VARDESC getVarDesc(int index) {
PointerByReference ppVarDesc = new PointerByReference();
HRESULT hr = this.typeInfo.GetVarDesc(new UINT(index), ppVarDesc);
COMUtils.checkRC(hr);
return new VARDESC(ppVarDesc.getValue());
}
Aggregations