无法使用 JNA 访问 IActiveDesktop 接口(不支持此类接口(HRESULT:80004002)
Unable to access the IActiveDesktop interface with JNA (No such interface supported(HRESULT: 80004002)
我正在尝试使用 IActiveDesktop 界面更改 windows 7 上的桌面墙纸。所以我开始我的项目,我首先使用 SystemParametersInfo method using the User32 class. But there isn't fade effect and I can't modify the image position. After some research, I found the IActiveDesktop interface and this 。我接受了答案并对其进行了调整。但是当我 运行 我的代码时,它抛出 Exception in thread "main" com.sun.jna.platform.win32.COM.COMException: No such interface supported(HRESULT: 80004002)
.
在这里你可以找到我的代码:
首先是代表 IActiveDesktop 接口的 class
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.COM.COMUtils;
import com.sun.jna.platform.win32.COM.Unknown;
import com.sun.jna.platform.win32.*;
import com.sun.jna.ptr.PointerByReference;
import static com.sun.jna.platform.win32.Ole32.INSTANCE;
public class ActiveDesktop extends Unknown {
// {75048700-EF1F-11D0-9888-006097DEACF9}
// {F490EB00-1240-11D1-9888-006097DEACF9}
private static final Guid.GUID CLSID_ActiveDesktop = getGUID("{75048700-EF1F-11D0-9888-006097DEACF9}");
private static final Guid.GUID IID_IActiveDesktop = getGUID("{F490EB00-1240-11D1-9888-006097DEACF9}");
private static Guid.GUID getGUID(String guidStr) {
Guid.GUID guid = new Guid.GUID();
INSTANCE.IIDFromString(guidStr, guid);
return guid;
}
private ActiveDesktop(Pointer pvInstance) {
super(pvInstance);
}
public static ActiveDesktop create(){
PointerByReference p = new PointerByReference();
WinNT.HRESULT hr = INSTANCE.CoCreateInstance(CLSID_ActiveDesktop, null, WTypes.CLSCTX_INPROC_SERVER, IID_IActiveDesktop, p); // THE EXCEPTION IS THROW HERE
COMUtils.checkRC(hr);
return new ActiveDesktop(p.getValue());
}
}
以及仅加载 Ole32 库和 IActiveDesktop 接口的 Main:
import com.sun.jna.platform.win32.Ole32;
public class Main {
public static void main(String[] args) {
Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED);
try {
ActiveDesktop desktop = ActiveDesktop.create();
} finally {
Ole32.INSTANCE.CoUninitialize();
}
}
}
经过大量谷歌搜索后,我找不到答案。谁能帮我?可能答案是 在这种情况下,请向我解释哪里出了问题。谢谢。
注意:我是法国人,所以我的英语并不完美。对不起...
我终于找到了解决办法。即初始化Ole32时将Ole32.COINIT_MULTITHREADED
替换为Ole32.COINIT_APARTMENTTHREADED
。
我正在尝试使用 IActiveDesktop 界面更改 windows 7 上的桌面墙纸。所以我开始我的项目,我首先使用 SystemParametersInfo method using the User32 class. But there isn't fade effect and I can't modify the image position. After some research, I found the IActiveDesktop interface and this Exception in thread "main" com.sun.jna.platform.win32.COM.COMException: No such interface supported(HRESULT: 80004002)
.
在这里你可以找到我的代码:
首先是代表 IActiveDesktop 接口的 class
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.COM.COMUtils;
import com.sun.jna.platform.win32.COM.Unknown;
import com.sun.jna.platform.win32.*;
import com.sun.jna.ptr.PointerByReference;
import static com.sun.jna.platform.win32.Ole32.INSTANCE;
public class ActiveDesktop extends Unknown {
// {75048700-EF1F-11D0-9888-006097DEACF9}
// {F490EB00-1240-11D1-9888-006097DEACF9}
private static final Guid.GUID CLSID_ActiveDesktop = getGUID("{75048700-EF1F-11D0-9888-006097DEACF9}");
private static final Guid.GUID IID_IActiveDesktop = getGUID("{F490EB00-1240-11D1-9888-006097DEACF9}");
private static Guid.GUID getGUID(String guidStr) {
Guid.GUID guid = new Guid.GUID();
INSTANCE.IIDFromString(guidStr, guid);
return guid;
}
private ActiveDesktop(Pointer pvInstance) {
super(pvInstance);
}
public static ActiveDesktop create(){
PointerByReference p = new PointerByReference();
WinNT.HRESULT hr = INSTANCE.CoCreateInstance(CLSID_ActiveDesktop, null, WTypes.CLSCTX_INPROC_SERVER, IID_IActiveDesktop, p); // THE EXCEPTION IS THROW HERE
COMUtils.checkRC(hr);
return new ActiveDesktop(p.getValue());
}
}
以及仅加载 Ole32 库和 IActiveDesktop 接口的 Main:
import com.sun.jna.platform.win32.Ole32;
public class Main {
public static void main(String[] args) {
Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED);
try {
ActiveDesktop desktop = ActiveDesktop.create();
} finally {
Ole32.INSTANCE.CoUninitialize();
}
}
}
经过大量谷歌搜索后,我找不到答案。谁能帮我?可能答案是
注意:我是法国人,所以我的英语并不完美。对不起...
我终于找到了解决办法。即初始化Ole32时将Ole32.COINIT_MULTITHREADED
替换为Ole32.COINIT_APARTMENTTHREADED
。