Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
GetObject (gdi32)

C# Signature:

static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject);

VB.NET Signature:

<DllImport("gdi32.dll")> _
Private Shared Function GetObject(hgdiobj As IntPtr, cbBuffer As Integer, lpvObject As IntPtr) As Integer
End Function

User-Defined Types:



Had a terrible time getting this to work to retrieve a BITMAP object from a HBITMAP, this code finally worked.

(EDIT: Before going through all this check out the tips & tricks section for an official API to do this)

BITMAP bmpScreen;

GCHandle hndl = GCHandle.Alloc(bmpScreen, GCHandleType.Pinned);

IntPtr ptrToBitmap = hndl.AddrOfPinnedObject();

GDI32.GetObject(hBitmap, Marshal.SizeOf<GDI32.BITMAP>(), ptrToBitmap);

bmpScreen = Marshal.PtrToStructure<GDI32.BITMAP>(ptrToBitmap);


Tips & Tricks:

A better option than the above example would be to leverage Image.FromHbitmap

Image.FromHbitmap Documentation on MSDN:

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

GetObject on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version