This topic has not yet been rated - Rate this topic

GetClassLongPtr function

Applies to: desktop apps only

Retrieves the specified value from the WNDCLASSEX structure associated with the specified window.

Note  To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetClassLongPtr. When compiling for 32-bit Windows, GetClassLongPtr is defined as a call to the GetClassLong function.

Syntax

ULONG_PTR WINAPI GetClassLongPtr(
  __in  HWND hWnd,
  __in  int nIndex
);

Parameters

hWnd [in]

Type: HWND

A handle to the window and, indirectly, the class to which the window belongs.

nIndex [in]

Type: int

The value to be retrieved. To retrieve a value from the extra class memory, specify the positive, zero-based byte offset of the value to be retrieved. Valid values are in the range zero through the number of bytes of extra class memory, minus eight; for example, if you specified 24 or more bytes of extra class memory, a value of 16 would be an index to the third integer. To retrieve any other value from the WNDCLASSEX structure, specify one of the following values.

ValueMeaning
GCW_ATOM
-32

Retrieves an ATOM value that uniquely identifies the window class. This is the same atom that the RegisterClassEx function returns.

GCL_CBCLSEXTRA
-20

Retrieves the size, in bytes, of the extra memory associated with the class.

GCL_CBWNDEXTRA
-18

Retrieves the size, in bytes, of the extra window memory associated with each window in the class. For information on how to access this memory, see GetWindowLongPtr.

GCLP_HBRBACKGROUND
-10

Retrieves a handle to the background brush associated with the class.

GCLP_HCURSOR
-12

Retrieves a handle to the cursor associated with the class.

GCLP_HICON
-14

Retrieves a handle to the icon associated with the class.

GCLP_HICONSM
-34

Retrieves a handle to the small icon associated with the class.

GCLP_HMODULE
-16

Retrieves a handle to the module that registered the class.

GCLP_MENUNAME
-8

Retrieves the pointer to the menu name string. The string identifies the menu resource associated with the class.

GCL_STYLE
-26

Retrieves the window-class style bits.

GCLP_WNDPROC
-24

Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure.

 

Return value

Type:

Type: ULONG_PTR

If the function succeeds, the return value is the requested value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Reserve extra class memory by specifying a nonzero value in the cbClsExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

GetClassLongPtrW (Unicode) and GetClassLongPtrA (ANSI)

See also

Reference
GetWindowLongPtr
RegisterClassEx
SetClassLongPtr
WNDCLASSEX
Conceptual
Window Classes

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
vb.net example for both 32 bit and 64 bit

If you try to call GetClassLongPtr on a 32 bit OS or from a process running in wow64 mode (32 bit emulation) on a 64 bit OS then you will receive an EntryPointNotFound exception. Same for if you try to call GetClassLong from a 64 bit process.
Here is an example of a wrapper function (and the two API definitions required to use it) that can be called instead of calling the APIs directly, to avoid the issue described above:

<DllImportAttribute("user32.dll", EntryPoint:="GetClassLongW")> _
Public Shared Function GetClassLong(<InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As IntPtr
End Function
<DllImportAttribute("user32.dll", EntryPoint:="GetClassLongPtrW")> _
Public Shared Function GetClassLongPtr(<InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As IntPtr
End Function

 

Private Shared Function GetClassLongBoth(ByVal hwnd As IntPtr, ByVal nIndex As Integer) As IntPtr
    If IntPtr.Size = 4 Then
            'Must be a 32 bit OS or 32 bit process running on 64 bit OS
            Return GetClassLong(hwnd, nIndex)
    Else
            'Must be a 64 bit process
            Return GetClassLongPtr(hwnd, nIndex)
    End If
End Function