Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Streamline Your API Declares, Part 1

Most Windows API routines are functions and must be declared as such, but in many cases we are not really interested in their return value. The SendMessage function, for example, depending on the message sent, might not return any significant value. Even in this case, however, we are compelled to call it as a function, writing something like:

Dim dummy As Integer
dummy = SendMessage(Text1.hWnd, _
        WM_PASTE, 0, 0&)

In other words, you are forced to declare more variables and make your code less readable only because of a syntactical constraint of Visual Basic. Luckily, you can add an aliased Declare which converts SendMessage to a Sub:

Declare Sub SendMessageSub Lib "User" _
        Alias "SendMessage" _
        (ByVal hWnd%, ByVal msg%, ByVal _
        wParam, lParam As Any)

Now you can call SendMessage and discard its return value:

SendMessageSub Text1.hWnd, WM_PASTE, _
        0, ByVal 0&

Note that your code will also be slightly faster because you save an assignment and do not waste any time dimensioning a dummy variable.

Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date