use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class ObjectFactory method discoverClsId.
GUID discoverClsId(ComObject annotation) {
assert COMUtils.comIsInitialized() : "COM not initialized";
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 = Ole32.INSTANCE.CLSIDFromProgID(progIdStr, rclsid);
COMUtils.checkRC(hr);
return rclsid;
} else {
throw new COMException("ComObject must define a value for either clsId or progId");
}
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class Ole32Util method getStringFromGUID.
/**
* Convert a GUID into a string.
* @param guid
* GUID.
* @return
* String representation of a GUID.
*/
public static String getStringFromGUID(GUID guid) {
GUID pguid = new GUID(guid.getPointer());
int max = 39;
char[] lpsz = new char[max];
int len = Ole32.INSTANCE.StringFromGUID2(pguid, lpsz, max);
if (len == 0) {
throw new RuntimeException("StringFromGUID2");
}
lpsz[len - 1] = 0;
return Native.toString(lpsz);
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class Shell32Util method getKnownFolderPath.
/**
* Retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID. This function replaces
* {@link #getFolderPath}. That older function is now simply a wrapper for getKnownFolderPath
* @param guid the KNOWNFOLDERS GUID as defined in {@link KnownFolders}
* @return the path of the known folder. The returned path does not include a trailing backslash. For example,
* "C:\Users" is returned rather than "C:\Users\".
* @throws Win32Exception if the guid references a KNOWNFOLDERID which does not have a path (such as a folder marked
* as KF_CATEGORY_VIRTUAL) or that the KNOWNFOLDERID is not present on the system. Not all KNOWNFOLDERID values are
* present on all systems.
*/
public static String getKnownFolderPath(GUID guid) throws Win32Exception {
int flags = ShlObj.KNOWN_FOLDER_FLAG.NONE.getFlag();
PointerByReference outPath = new PointerByReference();
HANDLE token = null;
HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);
if (!W32Errors.SUCCEEDED(hr.intValue())) {
throw new Win32Exception(hr);
}
String result = outPath.getValue().getWideString(0);
Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
return result;
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class ObjectFactory method createObject.
/**
* Creates a new COM object (CoCreateInstance) for the given progId and
* returns a ProxyObject for the given interface.
*/
public <T> T createObject(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 = 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;
}
use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.
the class Ole32Util method getGUIDFromString.
/**
* Convert a string to a GUID.
* @param guidString
* String representation of a GUID, including { }.
* @return
* A GUID.
*/
public static GUID getGUIDFromString(String guidString) {
GUID lpiid = new GUID();
HRESULT hr = Ole32.INSTANCE.IIDFromString(guidString, lpiid);
if (!hr.equals(W32Errors.S_OK)) {
throw new RuntimeException(hr.toString());
}
return lpiid;
}
Aggregations