Jump to content
Sign in to follow this  

BSPlayer GetFileName (C++ to Autoit)

Recommended Posts



I need some help to convert the following C++ code to autoit:

;~ // char buf[MAX_PATH];
;~ // void *adr;
;~ //
;~ // adr=&buf;
;~ // cds.dwData=BSP_GetFileName;
;~ // cds.lpData=&adr;
;~ // cds.cbData=4;
;~ // SendMessage(bsp_hand,WM_COPYDATA,appHWND,(LPARAM)&cds);
;~ // available in BSPlayer version 0.84.484+
;~ //
;~ // appHWND is calling application window handle
;~ // File name will be copied to buf
;~ //
;~ // Get open file name
;~ #define BSP_GetFileName 0x1010B

What I got so far is:

#Include <SendMessage.au3>
$BS_FileName = BSP_GetFileName()
MsgBox(0, "BSPlayer File Name", $BS_FileName)
Func BSP_GetFileName()
     $hWndHandle = WinGetHandle("[CLASS:BSPlayer]")
     $WM_COPYDATA = 0x004A
     $BSP_GetFileName = 0x1010B
     $buf = DllStructCreate("CHAR[128]")
     $cds = DllStructCreate ("int;ptr;int")
     DllStructSetData ($cds, 1, $BSP_GetFileName)
     DllStructSetData ($cds, 2, DllStructGetPtr($buf))
     DllStructSetData ($cds, 3, 4)
     _SendMessage($hWndHandle, $WM_COPYDATA, 0, $cds)
     Return DllStructGetData($buf, 1)

but, of course, it doesn't work.

The function should return the file name currently playing in BSPlayer.

Thank You!

Edited by mikered82

Share this post

Link to post
Share on other sites

I did look in help file, but i don't know what I did wrong.

If you do, please tell me!

Share this post

Link to post
Share on other sites

_SendMessage($hWndHandle, $WM_COPYDATA, 0, $cds)

_SendMessage($hWndHandle, $WM_COPYDATA, 0, DllStructGetPtr($cds))

Yes, it was a mistake, but it still doesn't work. :mellow:

Share this post

Link to post
Share on other sites

Curious, how did you come up with this struct?

$cds = DllStructCreate ("int;ptr;int")

These are backwards:

DllStructSetData ($cds, 2, DllStructGetPtr($buf))
DllStructSetData ($cds, 3, 4)

bsp_hnd is missing; no idea where/what that is.

appHwnd should be in the wparam


I'd imagine it to look more like:

Func _BSP_GetFileName()
    Local $h_bsphnd = 0 ; No idea what this is
    Local $h_wnd = WinGetHandle("[CLASS:BSPlayer]")
    If Not IsHWnd($h_wnd) Then Return SetError(1, 0, 0)

    Local Static $__WM_COPYDATA = 0x004A
    Local Static $BSP_GETFILENAME = 0x1010B
    Local Static $t_buff = DllStructCreate("CHAR[256]")
    Local Static $p_buff = DllStructGetPtr($t_buff)

    Local Static $tagCOPYDATASTRUCT = "ptr dwData;uint cbData;ptr lpData"
    Local Static $t_cbs = DllStructCreate($tagCOPYDATASTRUCT)
    DllStructSetData($t_cbs, "dwData", $BSP_GETFILENAME)
    DllStructSetData($t_cbs, "cbData", 4)
    DllStructSetData($t_cbs, "lpData", $p_buff)
    Local Static $p_cbs = DllStructGetPtr($cbs)

    DllCall("User32.dll", "int", "SendMessage", _
        "hwnd", $h_bsphnd, "uint", $__WM_COPYDATA, _
        "wparam", $h_wnd, "lparam", $p_cbs)
    Return DllStructGetData($t_buff, 1)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.