Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic RegisterClipboardFormat Return value Conversion Solution

Status
Not open for further replies.

BinarySon

Programmer
Dec 8, 2008
1
0
0
US
I ran across a thread looking for the Declaration for the RegisterClipboardFormat and discovered a problem I hadn't yet encountered... (See thread 713-700610).

The API Call returns a Long value, which in that post it's mentioned that the value is in excess of 40000 - Beyond the limit of VB's integer, which is what is the Data Type for DataObject.GetData/SetData - Here's the solution...

Visual Basic doesn't have an unsigned 16 bit integer... But GetData/SetData doesn't care about the sign. So all we have to do is convert that return unsigned integer (as a Long) into the equivalent signed integer by...

Dim fmt As Integer
Dim rfmt As Long
rfmt = RegisterClipboardFormat("NewClipboardFormat")
'Take the Two's complete of the return value and it
'will give you the absolute value of the return (when
'interpreted as a negative number). Then just restore the
'sign
fmt = -(rfmt Xor (2 ^ 16 - 1)) + 1


I tried ORing the returned long with an Integer to achieve the same end but VB wouldn't allow it...

If you've followed along this far, you might also want to consider just using the following declaration instead:

Public Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal FormatName As String) As Integer

Values in excess of the upper positive limit of an Integer will be returned as a negative number...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top