|
15 | 15 | import com.sun.jna.Native; |
16 | 16 | import com.sun.jna.Pointer; |
17 | 17 | import com.sun.jna.WString; |
| 18 | +import com.sun.jna.platform.win32.BaseTSD.SIZE_T; |
18 | 19 | import com.sun.jna.platform.win32.Guid.CLSID; |
19 | 20 | import com.sun.jna.platform.win32.Guid.GUID; |
20 | 21 | import com.sun.jna.platform.win32.WinDef.LPVOID; |
@@ -214,4 +215,56 @@ HRESULT CoCreateInstance(GUID rclsid, Pointer pUnkOuter, int dwClsContext, |
214 | 215 | */ |
215 | 216 | HRESULT CLSIDFromString(WString lpsz, CLSID.ByReference pclsid); |
216 | 217 |
|
| 218 | + /** |
| 219 | + * Allocates a block of task memory in the same way that IMalloc::Alloc does. CoTaskMemAlloc uses the default |
| 220 | + * allocator to allocate a memory block in the same way that IMalloc::Alloc does. It is not necessary to call the |
| 221 | + * CoGetMalloc function before calling CoTaskMemAlloc. |
| 222 | + * <br/><br/>The initial contents of the returned memory block are |
| 223 | + * undefined - there is no guarantee that the block has been initialized. The allocated block may be larger than cb |
| 224 | + * bytes because of the space required for alignment and for maintenance information. |
| 225 | + * <br/><br/> |
| 226 | + * If cb is 0, CoTaskMemAlloc |
| 227 | + * allocates a zero-length item and returns a valid pointer to that item. If there is insufficient memory available, |
| 228 | + * CoTaskMemAlloc returns NULL. Applications should always check the return value from this function, even when |
| 229 | + * requesting small amounts of memory, because there is no guarantee that the memory will be allocated. |
| 230 | + * @param cb The size of the memory block to be allocated, in bytes. |
| 231 | + * @return If the function succeeds, it returns the allocated memory block. Otherwise, it returns NULL. |
| 232 | + */ |
| 233 | + LPVOID CoTaskMemAlloc(SIZE_T cb); |
| 234 | + |
| 235 | + /** |
| 236 | + * Changes the size of a previously allocated block of task memory. This function changes the size of a previously |
| 237 | + * allocated memory block in the same way that IMalloc::Realloc does. It is not necessary to call the CoGetMalloc |
| 238 | + * function to get a pointer to the OLE allocator before calling CoTaskMemRealloc. |
| 239 | + * <br/><br/> |
| 240 | + * The pv parameter points to the |
| 241 | + * beginning of the memory block. If pv is NULL, CoTaskMemRealloc allocates a new memory block in the same way as |
| 242 | + * the CoTaskMemAlloc function. If pv is not NULL, it should be a pointer returned by a prior call to |
| 243 | + * CoTaskMemAlloc. |
| 244 | + * <br/><br> |
| 245 | + * The cb parameter specifies the size of the new block. The contents of the block are unchanged up |
| 246 | + * to the shorter of the new and old sizes, although the new block can be in a different location. Because the new |
| 247 | + * block can be in a different memory location, the pointer returned by CoTaskMemRealloc is not guaranteed to be the |
| 248 | + * pointer passed through the pv argument. If pv is not NULL and cb is 0, then the memory pointed to by pv is freed. |
| 249 | + * <br/><br/> |
| 250 | + * CoTaskMemRealloc returns a void pointer to the reallocated (and possibly moved) memory block. The return value is |
| 251 | + * NULL if the size is 0 and the buffer argument is not NULL, or if there is not enough memory available to expand |
| 252 | + * the block to the specified size. In the first case, the original block is freed; in the second case, the original |
| 253 | + * block is unchanged. The storage space pointed to by the return value is guaranteed to be suitably aligned for |
| 254 | + * storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value. |
| 255 | + * @param pv A pointer to the memory block to be reallocated. This parameter can be NULL. |
| 256 | + * @param cb The size of the memory block to be reallocated, in bytes. This parameter can be 0. |
| 257 | + * @return If the function succeeds, it returns the reallocated memory block. Otherwise, it returns NULL. |
| 258 | + */ |
| 259 | + LPVOID CoTaskMemRealloc(LPVOID pv, SIZE_T cb); |
| 260 | + |
| 261 | + /** |
| 262 | + * Frees a block of task memory previously allocated through a call to the {@link #CoTaskMemAlloc} or |
| 263 | + * {@link #CoTaskMemRealloc} function. The function uses the default OLE allocator. The number of bytes |
| 264 | + * freed equals the number of bytes that were originally allocated or reallocated. After the call, the memory block |
| 265 | + * pointed to by pv is invalid and can no longer be used. |
| 266 | + * @param pv A pointer to the memory block to be freed. If this parameter is NULL, the function has no effect. |
| 267 | + */ |
| 268 | + void CoTaskMemFree(LPVOID pv); |
| 269 | + |
217 | 270 | } |
0 commit comments