View Single Post
  #18 (permalink)  
Old 21st March 2007
llai llai is offline
Junior Member
BS.Player Newbie
 
Join Date: Mar 2007
Location: Romania
Posts: 1
Rep Power: 0
llai is an unknown quantity at this point
Default Re:BSP_GetFileName and VB 6

This the correct method.
Try it and tell me if it works.

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 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, vbNullString)
If hWndBSPlayer = 0 Then 'can't find BSPlayer
BSGetCurrentFile = ""
Exit Function
End If
Dim buffer As String

Dim cds As COPYDATASTRUCT

buffer = Space$(256)
cds.dwData = BSP_GetFileName
cds.lpData = VarPtr(buffer)
cds.cbData = 4

RetVal = CopyDataSendMessage(hWndBSPlayer, WM_COPYDATA, Form1.hwnd, cds)
buffer = StrConv(buffer, vbUnicode)
nullpos = InStr(buffer, vbNullChar)
If nullpos > 1 Then BSGetCurrentFile = Left(buffer, nullpos - 1)
End Function
Reply With Quote
 

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