×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Visual Basic RegisterClipboardFormat Return value Conversion Solution

Visual Basic RegisterClipboardFormat Return value Conversion Solution

Visual Basic RegisterClipboardFormat Return value Conversion Solution

(OP)
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...
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close