[英]Jna E_OUTOFMEMORY
I wrote the equivavlent Java method for this c Method:我为此 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();
When I run the c method erverything works normal and "SUCCEEDED" is printed out.当我运行 c 方法时,一切正常,并打印出“SUCCEEDED”。
But wehen I run the Java method the HRESULT hi always returns -2147024882 Which means E_OUTOFMEMORY.但是当我运行 Java 方法时,HRESULT hi 总是返回 -2147024882,这意味着 E_OUTOFMEMORY。
I don't know why this error is thrown but I hope anyone can help我不知道为什么会抛出这个错误,但我希望任何人都可以提供帮助
The error exactly happens in this lines:错误恰好发生在这一行:
HRESULT hh = item->GetImage(size, SIIGBF_RESIZETOFIT, &bit);
WinDef.HBITMAP bit = new WinDef.HBITMAP(bitP.getPointer());
The solution is that the SIZE struct can not be passed by value.解决的办法是SIZE结构体不能按值传递。 (in C++ it can). (在 C++ 中它可以)。 You have to create a class SIZEByValue that extends SIZE and implements Structure.ByValue.您必须创建一个扩展 SIZE 并实现 Structure.ByValue 的 SIZEByValue 类。 Now it is working.现在它正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.