GetClipboardFormatName function
Applies to: desktop apps only
Retrieves from the clipboard the name of the specified registered format. The function copies the name to the specified buffer.
Syntax
int WINAPI GetClipboardFormatName( __in UINT format, __out LPTSTR lpszFormatName, __in int cchMaxCount );
Parameters
- format [in]
-
Type: UINT
The type of format to be retrieved. This parameter must not specify any of the predefined clipboard formats.
- lpszFormatName [out]
-
Type: LPTSTR
The buffer that is to receive the format name.
- cchMaxCount [in]
-
Type: int
The maximum length, in characters, of the string to be copied to the buffer. If the name exceeds this limit, it is truncated.
Return value
Type: int
If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.
If the function fails, the return value is zero, indicating that the requested format does not exist or is predefined. To get extended error information, call GetLastError.
Remarks
Security Considerations
Using this function incorrectly might compromise the security of your program. For example, miscalculating the proper size of the lpszFormatName buffer, especially when the application is used in both ANSI and Unicode versions, can cause a buffer overflow. Also, note that the string is truncated if it is longer than the cchMaxCount parameter, which can lead to loss of information.
Examples
For an example, see Example of a Clipboard Viewer.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | GetClipboardFormatNameW (Unicode) and GetClipboardFormatNameA (ANSI) |
See also
- Reference
- EnumClipboardFormats
- RegisterClipboardFormat
- Conceptual
- Clipboard
Send comments about this topic to Microsoft
Build date: 3/6/2012
This document also fails to mention what the maximum possible size is for a name that could get dropped into the lpszFormatName buffer Microsoft's example code uses an 80 character buffer. The RegisterClipboardFormat() API documentation is also silent on this other than to note that it's a case-insensitive string. A scan of the registered formats from 0xC000 to 0xFFFF finds the names range from 3 to 113 characters on my system at this instant. Testing finds that RegisterClipboardFormat() returns error 87 ERROR_INVALID_PARAMETER if lpszFormatName is 256 characters or longer. Attempts to register a zero length name result in error 123 ERROR_INVALID_NAME. In other words, the lpszFormatName can be from 1 to 255 characters plus the terminating NUL. Thus using a 256 character buffer will work for most, if not all, systems.
- 9/10/2011
- Marc Kupper
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetClipboardFormatName(int format, StringBuilder lpString, int cchMax);
- 4/26/2009
- dmex
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetClipboardFormatName(ByVal format As Integer, ByVal lpString As StringBuilder, ByVal cchMax As Integer) As Integer
End Function
- 4/26/2009
- dmex
RegisterWindowMessage:
http://msdn2.microsoft.com/en-us/library/ms644947.aspx
See RegisterWindowMessage community content for details, or follow this newsgroup link:
http://groups.google.it/group/microsoft.public.vc.mfc/browse_thread/thread/f83f7c12c80e4ada/460bc4c43a844a37
Giovanni
- 2/21/2008
- Giovanni Dicanio