gpt4 book ai didi

java - Jna E_OUTOFMEMORY

转载 作者:行者123 更新时间:2023-11-30 16:26:49 27 4
gpt4 key购买 nike

我为这个 c 方法编写了等效的 Java 方法:

HRESULT h3 = CoInitializeEx(NULL, COINIT_MULTITHREADED);
HRESULT h4 = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

IShellItemImageFactory * item;


HRESULT h = SHCreateItemFromParsingName(L"C:\\Users\\Marcel\\Desktop\\CosmosKernel2Boot.iso", NULL, IID_IShellItemImageFactory, (void**)&item);

if (SUCCEEDED(h)) {

HBITMAP bit;

SIZE size = { 32,32 };

HRESULT hh = item->GetImage(size, SIIGBF_RESIZETOFIT, &bit);
if (SUCCEEDED(hh)) {
cout << "SUCCEEDED";
}
}
item->Release();

CoUninitialize();

Java:

Ole32Extra.INSTANCE.CoInitializeEx(null,Ole32.COINIT_MULTITHREADED);
Ole32Extra.INSTANCE.CoInitializeSecurity(null, -1, null, null, Ole32Extra.RPC_C_AUTHN_LEVEL_DEFAULT, Ole32Extra.RPC_C_IMP_LEVEL_IMPERSONATE, null, Ole32Extra.EOAC_NONE, null);

PointerByReference factory = new PointerByReference();

WinNT.HRESULT h5 = Shell32Extra.INSTANCE.SHCreateItemFromParsingName(new WString("C:\\Users\\Marcel\\Desktop\\Test.txt"),null,new Guid.REFIID(new Guid.IID(Shell32Extra.IID_IShellItemImageFactory)),factory);

if(COMUtils.SUCCEEDED(h5)) {
IShellItemImageFactory factory1 = new IShellItemImageFactory(factory.getValue());

PointerByReference bitP = new PointerByReference();

WinUser.SIZE size = new WinUser.SIZE(32,32);

WinNT.HRESULT hi = factory1.GetImage(size,0,bitP);

if(COMUtils.SUCCEEDED(hi)) {
WinDef.HBITMAP bit = new WinDef.HBITMAP(bitP.getPointer());

System.out.println("SUCCEEDED");
}else{
System.out.println(hi);
}
factory1.Release();
}else{
System.out.println(h5);
}
Ole32Extra.INSTANCE.CoUninitialize();

当我运行 c 方法时,一切正常,并打印出“SUCCEEDED”。

但是当我运行 Java 方法时,HRESULT hi 总是返回 -2147024882这意味着 E_OUTOFMEMORY。

我不知道为什么会抛出这个错误,但我希望任何人都可以提供帮助

错误正是发生在这一行中:

HRESULT hh = item->GetImage(size, SIIGBF_RESIZETOFIT, &bit);

WinDef.HBITMAP bit = new WinDef.HBITMAP(bitP.getPointer());

最佳答案

解决办法是SIZE结构不能按值传递。 (在 C++ 中可以)。您必须创建一个扩展 SIZE 并实现 Structure.ByValue 的类 SIZEByValue。现在它正在工作。

关于java - Jna E_OUTOFMEMORY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52953419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com