GetObject function
Retrieves information about a graphics object.
Syntax
C / C++
C#
VB.NET
int GetObject(
HGDIOBJ h,
int cbBuffer,
LPVOID lpvObject
);
[DllImport("gdi32.dll", SetLastError = true)]
static extern int GetObject(
IntPtr hObject,
int cbBuffer,
IntPtr lpvObject
);
Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (
ByVal hObject As IntPtr,
ByVal cbBuffer As Integer,
ByVal lpvObject As IntPtr
) As Integer
Parameters
| Parameter | Type | Description |
|---|---|---|
| h | HGDIOBJ | Handle to the graphics object. |
| cbBuffer | int | Size of the buffer pointed to by lpvObject, in bytes. |
| lpvObject | LPVOID | Pointer to a buffer that receives the object data. |
Return value
If the function succeeds, the return value is the number of bytes copied to the buffer. If the function fails, the return value is zero.
Remarks
Use GetObjectType to determine the type of the object before calling GetObject. The buffer size must be appropriate for the object type. Common uses include retrieving a BITMAP structure for a bitmap handle.
Example
The following example retrieves a BITMAP structure from a bitmap handle:
#include <windows.h>
#include <stdio.h>
int main()
{
HBITMAP hBmp = (HBITMAP)LoadImageW(NULL, L"example.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (!hBmp) { printf("LoadImage failed\\n"); return 1; }
BITMAP bmp;
int ret = GetObject(hBmp, sizeof(BITMAP), &bmp);
if (ret == 0) { printf("GetObject failed\\n"); return 1; }
printf("Width: %d, Height: %d, Bits/Pixel: %d\\n", bmp.bmWidth, bmp.bmHeight, bmp.bmBitsPixel);
DeleteObject(hBmp);
return 0;
}