Skip to content

Commit

Permalink
Merge pull request #373 from lwahonen/master
Browse files Browse the repository at this point in the history
Small COM fixes
  • Loading branch information
dblock committed Oct 24, 2014
2 parents 4616cfb + be9a1ed commit a0c705a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// TODO: Auto-generated Javadoc
/**
* Helper class to provide basic COM support.
*
*
* @author Tobias Wolf, [email protected]
*/
public class COMBindingBaseObject extends COMInvoker {
Expand Down Expand Up @@ -72,8 +72,9 @@ public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance) {
public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance,
int dwClsContext) {
// Initialize COM for this thread...
HRESULT hr = Ole32.INSTANCE.CoInitialize(null);

HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_APARTMENTTHREADED);
if (hr.intValue() == 1) // Already initialized, no problem
hr = new HRESULT(0);
if (COMUtils.FAILED(hr)) {
Ole32.INSTANCE.CoUninitialize();
throw new COMException("CoInitialize() failed!");
Expand Down Expand Up @@ -106,7 +107,9 @@ public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance,
public COMBindingBaseObject(String progId, boolean useActiveInstance,
int dwClsContext) throws COMException {
// Initialize COM for this thread...
HRESULT hr = Ole32.INSTANCE.CoInitialize(null);
HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_APARTMENTTHREADED);
if (hr.intValue() == 1) // Already initialized, no problem
hr = new HRESULT(0);

if (COMUtils.FAILED(hr)) {
this.release();
Expand Down Expand Up @@ -154,7 +157,7 @@ public COMBindingBaseObject(String progId, boolean useActiveInstance)

/**
* Gets the i dispatch.
*
*
* @return the i dispatch
*/
public IDispatch getIDispatch() {
Expand All @@ -163,7 +166,7 @@ public IDispatch getIDispatch() {

/**
* Gets the i dispatch pointer.
*
*
* @return the i dispatch pointer
*/
public PointerByReference getIDispatchPointer() {
Expand All @@ -172,7 +175,7 @@ public PointerByReference getIDispatchPointer() {

/**
* Gets the i unknown.
*
*
* @return the i unknown
*/
public IUnknown getIUnknown() {
Expand All @@ -181,7 +184,7 @@ public IUnknown getIUnknown() {

/**
* Gets the i unknown pointer.
*
*
* @return the i unknown pointer
*/
public PointerByReference getIUnknownPointer() {
Expand Down Expand Up @@ -270,7 +273,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult,

/**
* Ole method.
*
*
* @param nType
* the n type
* @param pvResult
Expand Down Expand Up @@ -301,7 +304,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult,

/**
* Ole method.
*
*
* @param nType
* the n type
* @param pvResult
Expand All @@ -328,7 +331,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult,

/**
* Check failed.
*
*
* @param hr
* the hr
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
try {
// open root key
phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT,
"CLSID", WinNT.KEY_ALL_ACCESS);
"CLSID", WinNT.KEY_READ);
// open subkey
InfoKey infoKey = Advapi32Util.registryQueryInfoKey(
phkResult.getValue(), WinNT.KEY_ALL_ACCESS);
phkResult.getValue(), WinNT.KEY_READ);

for (int i = 0; i < infoKey.lpcSubKeys.getValue(); i++) {
EnumKey enumKey = Advapi32Util.registryRegEnumKey(
Expand All @@ -141,9 +141,9 @@ public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
COMInfo comInfo = new COMInfo(subKey);

phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(),
subKey, WinNT.KEY_ALL_ACCESS);
subKey, WinNT.KEY_READ);
InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(
phkResult2.getValue(), WinNT.KEY_ALL_ACCESS);
phkResult2.getValue(), WinNT.KEY_READ);

for (int y = 0; y < infoKey2.lpcSubKeys.getValue(); y++) {
EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(
Expand Down

0 comments on commit a0c705a

Please sign in to comment.