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
|