[英]Jna E_OUTOFMEMORY
我為此 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();
爪哇:
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 類。 現在它正在工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.