Working with Windows API Procedures That Use Strings

The Declare statement's Alias clause is required when you call Windows API procedures that use strings to specify the correct character set. There are actually two formats for procedures that contain strings: ANSI and Unicode.

For example, the SetWindowText function does not really exist. Instead, you use two separate functions depending on whether you use ANSI or Unicode. The following code illustrates the ANSI version:

Private Declare Function SetWindowText Lib "user32" Alias _

"SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) _ As Long

The string that follows the Alias clause must be the procedure's true, case-sensitive name. Specify the ANSI version of functions in Visual Basic, because only Windows NT supports the Unicode versions. Use Unicode only when you're certain your application will run on Windows NT.

0 0

Post a comment