Fixed inheritance of LPVOID and simplified access to CoTaskMem*

Esse commit está contido em:
Martin Steiger
2014-05-25 17:32:13 +02:00
commit e52c4255d9
5 arquivos alterados com 20 adições e 22 exclusões
@@ -230,7 +230,7 @@ public interface Ole32 extends StdCallLibrary {
* @param cb The size of the memory block to be allocated, in bytes.
* @return If the function succeeds, it returns the allocated memory block. Otherwise, it returns NULL.
*/
LPVOID CoTaskMemAlloc(SIZE_T cb);
Pointer CoTaskMemAlloc(long cb);
/**
* Changes the size of a previously allocated block of task memory. This function changes the size of a previously
@@ -256,7 +256,7 @@ public interface Ole32 extends StdCallLibrary {
* @param cb The size of the memory block to be reallocated, in bytes. This parameter can be 0.
* @return If the function succeeds, it returns the reallocated memory block. Otherwise, it returns NULL.
*/
LPVOID CoTaskMemRealloc(LPVOID pv, SIZE_T cb);
Pointer CoTaskMemRealloc(Pointer pv, long cb);
/**
* Frees a block of task memory previously allocated through a call to the {@link #CoTaskMemAlloc} or
@@ -265,6 +265,6 @@ public interface Ole32 extends StdCallLibrary {
* pointed to by pv is invalid and can no longer be used.
* @param pv A pointer to the memory block to be freed. If this parameter is NULL, the function has no effect.
*/
void CoTaskMemFree(LPVOID pv);
void CoTaskMemFree(Pointer pv);
}
@@ -84,7 +84,7 @@ public abstract class Shell32Util {
}
String result = outPath.getValue().getWideString(0);
Ole32.INSTANCE.CoTaskMemFree(new LPVOID(outPath.getPointer().getLong(0)));
Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
return result;
}
@@ -978,7 +978,7 @@ public interface WinDef extends StdCallLibrary {
public static class PVOID extends PointerType {
public PVOID() {
// TODO Auto-generated constructor stub
super();
}
/**
@@ -992,25 +992,23 @@ public interface WinDef extends StdCallLibrary {
}
/**
* Message parameter.
* LPVOID is simply a Windows API typedef for void* - to pointer to any type so to speak.
*/
public static class LPVOID extends LONG_PTR {
public static class LPVOID extends PointerType {
/**
* Instantiates a new lpvoid.
* Instantiates a new instance to NULL.
*/
public LPVOID() {
this(0);
super();
}
/**
* Instantiates a new lpvoid.
*
* @param value
* the value
* Instantiates a new instance using a given pointer.
* @param p the pointer
*/
public LPVOID(long value) {
super(value);
public LPVOID(Pointer p) {
super(p);
}
}
@@ -110,21 +110,21 @@ public class Ole32Test extends TestCase {
}
public void testCoTaskMemAlloc() {
LPVOID ptr = Ole32.INSTANCE.CoTaskMemAlloc(new SIZE_T(256));
Pointer ptr = Ole32.INSTANCE.CoTaskMemAlloc(256);
assertTrue(ptr.longValue() != 0);
assertTrue(!ptr.equals(Pointer.NULL));
Ole32.INSTANCE.CoTaskMemFree(ptr);
}
public void testCoTaskMemRealloc() {
LPVOID ptr = Ole32.INSTANCE.CoTaskMemAlloc(new SIZE_T(256));
Pointer ptr = Ole32.INSTANCE.CoTaskMemAlloc(256);
assertTrue(ptr.longValue() != 0);
assertTrue(!ptr.equals(Pointer.NULL));
ptr = Ole32.INSTANCE.CoTaskMemRealloc(ptr, new SIZE_T(128));
ptr = Ole32.INSTANCE.CoTaskMemRealloc(ptr, 128);
assertTrue(ptr.longValue() != 0);
assertTrue(!ptr.equals(Pointer.NULL));
Ole32.INSTANCE.CoTaskMemFree(ptr);
}
@@ -139,7 +139,7 @@ public class Shell32Test extends TestCase {
GUID guid = KnownFolders.FOLDERID_Fonts;
HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);
Ole32.INSTANCE.CoTaskMemFree(new LPVOID(outPath.getPointer().getLong(0)));
Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
}