I'm trying to get the taskbar button ID for my App. I only need to do this once, so I figured I'd just loop through buttons, get the caption and compare it to my app's caption. I'm using TB_GETBUTTONTEXT to get the captions, but whilst its returning the length of the caption, it's not populating the buffer.

Here's the code:
VB Code:
  1. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
  2.     ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  3. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
  4.     ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  5. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
  6.     ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  7.  
  8. Public Const WM_USER = &H400
  9. Public Const TB_GETBUTTONTEXT = (WM_USER + 45)
  10.  
  11. Public Function GetAppsID(ByVal sCaption As String) As Long
  12.     Dim lhWnd As Long, N As Long, lLen As Long, sBuff As String
  13.     lhWnd = FindWindow("Shell_TrayWnd", vbNullString)
  14.     lhWnd = FindWindowEx(lhWnd, 0&, "ReBarWindow32", vbNullString)
  15.     lhWnd = FindWindowEx(lhWnd, 0&, "MSTaskSwWClass", vbNullString)
  16.     lhWnd = FindWindowEx(lhWnd, 0&, "ToolbarWindow32", vbNullString)
  17.    
  18.     Do
  19.         lLen = SendMessage(lhWnd, TB_GETBUTTONTEXT, N, Null)
  20.         If lLen = -1 Then Exit Do
  21.         sBuff = Space$(lLen + 1)
  22.         lLen = SendMessage(lhWnd, TB_GETBUTTONTEXT, N, sBuff)
  23.         Debug.Print N, lLen, Trim$(sBuff)
  24.         N = N + 1
  25.     Loop Until N = 50
  26. End Function
Any ideas?

be warned: passing the lParam ByVal causes an error in explorer.