View Single Post
  #1 (permalink)  
Old 8th June 2005
immortal immortal is offline
Junior Member
BS.Player Newbie
 
Join Date: Jun 2005
Posts: 3
Rep Power: 0
immortal is an unknown quantity at this point
Default BSP_GetFileName and VB 6

I'm trying to use the BSP_GetFileName routine in visual basic, however it always returns a buffer containing nothing but zeros. Here is the code I'm using:

Public Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As Long) As Long


Public Declare Function CopyDataSendMessage Lib "user32" Alias _
"SendMessageA" (ByVal WndID As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByRef lParam As COPYDATASTRUCT) As Long


Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
(ByVal lpString1 As String, ByVal lpString2 As String) _
As Long


Public Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long

End Type


Public Const WM_COPYDATA = &H4A
Public Const BSP_GetFileName = &H1010B
Public bspClass As String
Public hWndBSPlayer As Long
Public RetVal As Long

Public Function BSGetCurrentFile() As String
Dim nullpos As Integer
bspClass = "BSPlayer"
hWndBSPlayer = FindWindow(bspClass, 0)
If hWndBSPlayer = 0 Then 'can't find BSPlayer
BSGetCurrentFile = ""
Exit Function
End If
Dim buffer As String * 256

Dim cds As COPYDATASTRUCT
cds.dwData = BSP_GetFileName
cds.lpData = lstrcpy(buffer, buffer)
' Copies filename to itself. Nothing happens, but returns the address for the pointer to the string!
cds.cbData = 4

RetVal = CopyDataSendMessage(hWndBSPlayer, WM_COPYDATA, Form1.hwnd, cds)
nullpos = InStr(buffer, Chr(0))
If nullpos > 1 Then BSGetCurrentFile = Left(buffer, nullpos - 1)

End Function

the code executes correctly and CopyDataSendMessage returns a value of 1 but the currently open filename isn't returned. I'm using BSPlayer Pro
Version 1.22 Build 817, 24. Feb 2005. I am using a very similar routine to open a file, and that works fine. Any help would be appreciated.
Reply With Quote
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20